Thread: Passing function as argument to a DLL that use it in a thread

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    147

    Passing function as argument to a DLL that use it in a thread

    I am writting a DLL, with a function where I receive a function address of the calling process in order to call that remote function when I need in my code. The function has a string pointer as argument.

    In the DLL I have this global variable, where I define the pointer to the remote function:

    Code:
    int (__stdcall *f_status) (char *);
    One of the exported function in the DLL is:

    Code:
    INT __declspec(dllexport) __stdcall _MYDLL_RegisterStatusFunc (int (__stdcall *statusfunc) (char*)) {
    	f_status=statusfunc;
            return OK;
    }
    This function is called by the remote program, which I don't have the source code.

    In my DLL code, the calling program call this function. Then, if I call f_status function the call is OK. But I have code where I create a thread with beginthread.

    I make two call to f_status, One before thread begin: the call is OK. The second one is after thread creation, the first instruction in the thread, and the programs crash. it is like if thread creation destroy same kind of remote calls. If I don't call this remote function, the rest of the thread run OK.

    I have tried to write in a log file the content in bytes of the f_status, and the pointer itself; I see that before and after thread creation is the same.... so the remote address does not change..... only the execution of the call is what crash.

    Of course, I check before calling f_status that it is not NULL.

    I am using lcc32 compiler, free for non-comercial use.

    Do you know what's the problem?. If I make calls outside threads it works perfect.
    Any tip? Am I doing samething wrong?

    Thanks in advance.
    Kem
    Last edited by Kempelen; 02-26-2008 at 11:03 AM.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    I would first recommend a decent IDE that includes a debugger. You'll learn a lot more about your problem using a debugger. If you're going to jump into the world of multi-threading, you are going to have to take the debugger plunge as well.

    My guess is that the problem within the function pointed to by f_status. [Debuggers don't guess ]

    Free IDE suggestion: code blocks

    gg

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    More free IDEs: http://cpwiki.sf.net/Integrated_Development_Environment
    And if you want to hear my opinion, go for Visual Studio
    Very powerful IDE + debugger in one package.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Quote Originally Posted by Elysia View Post
    More free IDEs: http://cpwiki.sf.net/Integrated_Development_Environment
    And if you want to hear my opinion, go for Visual Studio
    Very powerful IDE + debugger in one package.

    Not to taint this thread but I use Netbeans6.0 with the gdb debugger = free, in addition to using splint I am golden.

    I would like to test VS, but that is costly.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Does the express edition not have a debugger in it?

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Express version is free and yes, it has a debugger.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing a byte and its bits to a function
    By rtarbell in forum C Programming
    Replies: 9
    Last Post: 12-04-2008, 09:24 AM
  2. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. passing a function as an argument
    By angelscars in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2005, 09:53 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM