passing pointer to string from exe to dll

This is a discussion on passing pointer to string from exe to dll within the C Programming forums, part of the General Programming Boards category; Im trying to pass a pointer to a string to a dll loaded at runtime so that i can modify ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    7

    passing pointer to string from exe to dll

    Im trying to pass a pointer to a string to a dll loaded at runtime so that i can modify the value of the string from the dll however I am getting buffer overruns. If anyone could shed some light on what im doing wrong it would be appreciated.


    http://www.dakotacom.net/~bthomas/dll.txt

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    >>sprintf(crc, "%x", test);

    Look up the second arg here

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    7
    it's not the sprintf call, i can take it out of the code completely and it still crashes...

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    7
    ups

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Stop bumping your thread and actually be useful for a change. Don't just say "it crashes" because that helps on one.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    the GetModuleFileName() could be expecting TCHAR's (that could be 2 wide if using UNICODE) and so using 100 + terminator bytes of your 50 byte buffer........
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User
    Join Date
    May 2003
    Posts
    7
    I am pretty positive it has to do with passing the pointer because I can modify the function and pass ints just fun, but as soon as I try to pass a pointer I get the buffer overrun. I'm stumped.

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Right...ok...I tried your code and there are a few nasties;

    • #include <iostream.h> - in a c file! Dont do it, C++ only when using that header
    • void (WINAPI*makeCRC)(char *crc); - no WINAPI declaration for a function you created yourself....if you made the function, it's using the C calling convention....WINAPI forces the stdcall convention...no doubt this is the cause of your crash
    • void (WINAPI*makeCRC)(char *crc); - again this isnt what it's supposed to be....you need to use this line as part of a typedef, then use that to create the function pointer


    so the func declaration in the exe will look like this

    Code:
    typedef void (*MAKECRC)(char *crc);
    MAKECRC makeCRC;

  9. #9
    Registered User
    Join Date
    May 2003
    Posts
    7
    Made that change and now im getting an error trying to compile :/

    error C2440: '=' : cannot convert from 'FARPROC' to 'MAKECRC'

    on line:

    makeCRC=GetProcAddress((HMODULE)hLib, "makeCRC");

  10. #10
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Then cast it

    makeCRC=(MAKECRC)GetProcAddress(hLib, "makeCRC");

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  3. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  4. Replies: 4
    Last Post: 03-03-2006, 01:11 AM
  5. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-26-2003, 11:03 PM

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