LoadLibrary() from another DLL

I'm writing an set of ID 'tags' in dll form for the beta testers of my Half-Life mod (so if they leak my beta i'll know who it was) but i'm running into a problem.

i'm running this code:

HMODULE idlib = LoadLibrary("mod\\dlls\\id");
if(idlib == NULL)
      strcpy(szRejectReason, "Unable to load id.dll");
      return FALSE;

the library loads correctly at this point.
i tried to get a pointer to the one and only function in the dll with this code:

typedef char* (*MYPROC)(void);

MYPROC func;
func = (MYPROC)GetProcAddress(idlib, "ID_GetTesterName");

but func is always null after this call, so I'm unable to get the Tester's ID.
So, I'm reduced to only making the id.dll be present to run the game; I had planned on only allowing one player with each ID in a multiplayer game at once (during the beta phase, anyway) so Joe can't share the mod with his friends.

Now, I may have had the typedef wrong in my original code, but would that have made func null?
I will try it once more in a moment, but i'd appreciate any help.
(I'd link the dll i'm compiling with id.lib at compile-time but then id.dll would have to be in the same folder as hl.exe, and I want it at the least in the mod folder.)
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It seems that you are a victim of C++ name decoration. Be sure to declare 'ID_GetTesterName()' as

extern "C" __declspec(dllexport) char* ID_GetTesterName ( void);

If you are still experiencing troublen, use

dumpbin.exe /exports id.dll

to see what functions actually are listed in the export table.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BTW, a sure way to ensure that these problems do not occur is using .def files, e.g.

DESCRIPTION  'extension for my program'

You are either not exporting the function, or it's name has been decorated.  You can use DEPENDS.EXE or maybe DUMPBIN to find out.  In the DLL that exports, use this in the source code:

__declspec(dllexport) void PASCAL ID_GetTesterName(void)
      return( 1234 );

Your .DEF file for that DLL, should look something like this:
; ID_DLL.def : Declares the module parameters for the DLL.

DESCRIPTION  'ID DEF Windows Dynamic Link Library'

    ; Explicit exports can go here
ID_GetTesterName     @1

That should fix you up, unless I misunderstand the question.

-- Dan
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

heronblademasterAuthor Commented:
thanks, jkr, that extern "C" thing did it.
and to Dan (which is my name too :D) thanks too, i'll do that from now on
i gave jkr more points because he gave me a more immediate solution
thanks again all
jkr is just a pointhound on a summit-push for his C++ 'Genius' certificate.  You should ignore anything he says. :-))))

-- Dan
heronblademasterAuthor Commented:
Hum, if so, I better take care of my W2k cert, that's just 7k away :o)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.