Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

temp_ie_cant_thinkof_name

my first dll doesn't work

This topic is 5237 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here are the two projects built seperately:

//myapp.cpp
//a console project 
//trys to link and call dll at run-time

#include <windows.h>
#include <stdio.h>

//I tried extern "C" {} on this, but didn't help
__declspec(dllimport) void myPrintString(char *string);

typedef void (*myPrintStringPtr)(char *string);

void main(void)
{
   HINSTANCE dll = LoadLibrary("mydll");
   if(dll != NULL)
   {
      myPrintStringPtr myPrint =    (myPrintStringPtr)GetProcAddress(dll, "myPrintString");
      if(!myPrint)
      {
         FreeLibrary(dll);
      }
      else 
      {
         myPrint("I'm supposed to see this, but I'm not");
         printf("If you see this, then I got the address of the function, right???");
         FreeLibrary(dll);
      }
}

//mydll.cpp
//I put the output dll into the release or debug directory of myapp.cpp

#include <stdio.h>

__declspec(dllexport) void myPrintString(char *string);

void myPrintString(char *string)
{
   printf("%s \n", string);
}

 
That should compile, but I just made that up for simplicity. No matter what I try to call in my exported-frm-dll function, it won't get called... I tried doing this in Win32 app and in console. I can run it and I can verify that I loaded the library and got the exported function with GetProc, but I can't call it>_< Anyhow, I'm glad I caught these problems now, before I started my actual project around a dll. Edit: why aren't the source tags working? [edited by - temp_ie_cant_thinkof_name on March 21, 2004 5:33:25 PM]

Share this post


Link to post
Share on other sites
Advertisement
EDIT TO ABOVE: Actually, I DID NOT get as far as the printf statement. So, I''m not linking, and I''m not calling GetProc. Does anyone have any idea why? I put the dll in the same directory as the app''s exe, and the system is supposed to search there first...

Share this post


Link to post
Share on other sites
quote:
Original post by SiCrane
Did you try using "mydll.dll" instead of just "mydll"?


All, the examples I''ve seen show "nameofdll" w/o the externsion. So I guess LoadLibrary() knows what''s meant. But just in case, I''ll try that even though LoadLib() says it''s working, hmmm...

Share this post


Link to post
Share on other sites
Well that was a suggestion for when you said that you LoadLibrary() wasn''t working. What does GetLastError() say after a fail call?

Share this post


Link to post
Share on other sites
Okay, the extension part in the string (".dll"), doesn''t matter, and the extern "C" doesn''t matter. This is what I''ve deduced. Question: in my test app, I''m sending the file name as a string with space characters in it, because that''s what I named the dll ("My Dll Blah"). Does LoadLibrary() mind the spaces??? I''ll get back to you with GetLastError, hold on.

Share this post


Link to post
Share on other sites
quote:
Original post by temp_ie_cant_thinkof_name
Does LoadLibrary() mind the spaces?
I shouldn''t think so, given that Windows supports spaces in filenames generally and that your call to LoadLibrary returns successfully.

Share this post


Link to post
Share on other sites
Did you try doing a exported symbol dump from your dll to make sure that the symbol name you''re using is actually the symbol name of your function? It could be an issue with name mangling.

If that is the problem, my personal preferred solution is to add a .def file to when you link the dll.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!