CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2008
    Posts
    56

    Calling a C function

    Hi! I have a static library where I have a function defined like:

    EXPORT_API BOOL Function(...)

    where I have:

    #define EXPORT_API extern "C" __declspec( dllexport )

    I'm writing a C++ class in which I would like to call this function. So, I linked the .lib file, and I defined:

    extern "C" BOOL Function(...)

    at the top of my source. Unfortunaly, I noticed it simply doesn't enter the function... and my method doesn't go on. No crash and the application is still working correctly. Any idea what I've done wrong?
    Thanks guys!

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Calling a C function

    I know very little about the dllexport keyword. Is this function actually in a DLL, or just in a static library?

  3. #3
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Calling a C function

    Do you have the source code of the static-library? If yes, then just add it as another dependent project. Also make sure you set project dependency properly, AND that output generated by lib-project is actually used by your application.

    Then you'll be able to debug it.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  4. #4
    Join Date
    Feb 2008
    Posts
    56

    Re: Calling a C function

    To be sincere, I have a doubt... I was told it was a static library... but I see now the project from which the library is taken produces a DLL... Then it is not a static library, right? Anyway, I placed the DLL in my directory and it still has the same behavior. I will try with the way you suggested, unfortunately, as far as I can see from the messageboxes I placed, the function is simply not called. Thanks for your advice!

  5. #5
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Calling a C function

    Since you have source code of DLL, just include that project in the solution. Set dependencies, and make sure DLL and EXE goes in the same path. Then you can do single stepping into the DLL function. If you cannot do, there is something wrong, or something else that you aren't aware of, or not telling us.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  6. #6
    Join Date
    Feb 2008
    Posts
    56

    Re: Calling a C function

    It seems it simply doesn't go into that function and immediately stops the method which called the function of my library. I placed a breakpoint immediately before the call, and the breakpoint is hit. I place breakpoints even in the first instruction of the function and after the function and none of those is hit.

    However, I noticed that, despite my solution now contains the two projects, and dependencies are correctly set, the deploy doesn't place the dll in the directory with the others I use... Maybe I'm doing something wrong...

  7. #7
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Calling a C function

    Check if the same DLL is being loaded (in Output window)
    Also make sure DLL is build with debugging information enabled.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  8. #8
    Join Date
    Feb 2008
    Posts
    56

    Re: Calling a C function

    Among the other DLLs, that one is not listed in debug mode indeed. Maybe its related to the fact that I have to deploy it manually as I get an error in deploy which can be translated as "files exhausted".

  9. #9
    Join Date
    Feb 2008
    Posts
    56

    Re: Calling a C function

    I went back to the original way I was loading the DLL, by linking against the .lib file and providing the DLL. Now it seems the debugger is telling me the DLL is loaded, but still, when it reaches the function, nothing happens at all. The first instruction is not executed...

    EDIT: I made it work. Everything was fine, except the fact that there was some king of mistake in one parameter passed to the function. No compile nor runtime error was displayed. I corrected that and everything works now. Thanks!
    Last edited by Luc484; May 12th, 2010 at 06:00 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured