Convert c to c++

This is a discussion on Convert c to c++ within the C++ Programming forums, part of the General Programming Boards category; This code was made for c (dll), but it wont compile for c++. How can I convert it? Code: DWORD ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    15

    Convert c to c++

    This code was made for c (dll), but it wont compile for c++. How can I convert it?


    Code:
    DWORD ThreadID;
    int *time = (int*)0x0100579C; 
    DWORD WINAPI changeTime(LPVOID lParam) {
    while(1)
    if( *time == 6 ) { 
    *time = 100;
    sleep(1);
    }
    }
    BOOL APIENTRY DllMain(HINSTANCE hDll, DWORD callReason, LPVOID lpReserved) {
     if(callReason == DLL_PROCESS_ATTACH) {
                 CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&changeTime, 0, 0, &ThreadID);
     }   
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    15
    nvm not sure how to fix it
    Last edited by AlexWu; 05-05-2010 at 08:00 PM.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    15
    are here any programs that i can use to convert it?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Is there a reason it doesn't compile, or does the compiler just give up and not print any messages?

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    15
    Well if you remove "sleep(1);" it compiles. but it doesn't work (code works if its compiled in c)

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    What are you using to compile for C, and what are you using to compile for C++? (Windows has a Sleep, but it doesn't have a sleep.)

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    15
    i use dev-C++ for both c and cpp, i don't need sleep for dll to work.

  8. #8
    ...and never returned. StainedBlue's Avatar
    Join Date
    Aug 2009
    Posts
    168
    You use mingw to compile, not dev c++
    goto( comeFrom() );

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So is the problem that it doesn't compile, or doesn't work? If (a) what are the errors that you get? If (b) does it crash, or not do what you want? If (b2), what does it do that it shouldn't or vice versa?

  10. #10
    Registered User
    Join Date
    Dec 2009
    Posts
    24
    yeah, i did, and its still not sorting right.
    For example, the two text files:

    First:
    Code:
    3I hope this works
    Second:
    Code:
    1This program is awesome
    The second text file entered should come out first, but it doesn't.

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    15
    So is the problem that it doesn't compile, or doesn't work?
    doesn't work, when compiled in c++

    trying to use mingw but getting error "unrecognized option '-Wl,–add-stdcall-alias'"
    when trying to make .dll from .o file

    M-S-H, I have no idea what you are talking about

  12. #12
    ...and never returned. StainedBlue's Avatar
    Join Date
    Aug 2009
    Posts
    168
    Quote Originally Posted by AlexWu View Post
    doesn't work, when compiled in c++

    trying to use mingw but getting error "unrecognized option '-Wl,–add-stdcall-alias'"
    when trying to make .dll from .o file

    M-S-H, I have no idea what you are talking about
    ???

    So, you're saying it compiled, but didn't work as intended, but then you got a compiler error...... ? I'm lost.
    goto( comeFrom() );

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So take that option out of the command list (or make it --add-stdcall-alias which is what I think it's supposed to be).

  14. #14
    Registered User
    Join Date
    May 2010
    Posts
    15
    Sorry I wasn’t clear. I can compile this code on Dev C++ and Code blocks fine, but once I do DLL doesn’t do anything. This code only works if you compile it with C.

    MINGW gives me error when I try to compile dll (I can compile exe fine using mingw). I’m sure problem isn’t a compiler it something to do with a code when compile it on c++.

    I did lots of research on DLL injection with c++ but I’m lost since here is not good information on it.

  15. #15
    Registered User
    Join Date
    Jun 2005
    Posts
    6,259
    The code you have yields undefined behaviour, as you're writing to a specific address. That tends to make things break when you change compilers or compiler settings, let alone change languages (C to C++).

    Given that you are clearly doing a hack (I'm guessing cheating in a game or bypassing some program's registration checks), I'm guessing this thread - or your objective at any rate - is against site rules here
    Right 98% of the time, and don't care about the other 3%.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [33.8] Can I convert a pointer-to-function to a void*?
    By EVOEx in forum C++ Programming
    Replies: 40
    Last Post: 08-19-2009, 07:50 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Replies: 3
    Last Post: 08-21-2006, 06:42 AM
  4. Convert Char to Int Function
    By drdroid in forum C++ Programming
    Replies: 9
    Last Post: 02-19-2003, 11:53 AM
  5. please help ... to convert date to string
    By mel in forum C Programming
    Replies: 1
    Last Post: 06-12-2002, 10:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21