Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

LoadLibrary() from another DLL

Posted on 2003-11-17
7
Medium Priority
?
612 Views
Last Modified: 2010-04-01
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.)
thanks
HeronBlademaster
0
Comment
Question by:heronblademaster
  • 3
  • 2
  • 2
7 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 600 total points
ID: 9768365
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.
0
 
LVL 86

Expert Comment

by:jkr
ID: 9768371
BTW, a sure way to ensure that these problems do not occur is using .def files, e.g.

LIBRARY      ID
DESCRIPTION  'extension for my program'

EXPORTS
    ID_GetTesterName
0
 
LVL 49

Assisted Solution

by:DanRollins
DanRollins earned 400 total points
ID: 9768394
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.

LIBRARY      "ID"
DESCRIPTION  'ID DEF Windows Dynamic Link Library'

EXPORTS
    ; Explicit exports can go here
ID_GetTesterName     @1
=--==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

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

-- Dan
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:heronblademaster
ID: 9768444
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
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9768559
jkr is just a pointhound on a summit-push for his C++ 'Genius' certificate.  You should ignore anything he says. :-))))

-- Dan
0
 

Author Comment

by:heronblademaster
ID: 9768566
lol
0
 
LVL 86

Expert Comment

by:jkr
ID: 9768605
Hum, if so, I better take care of my W2k cert, that's just 7k away :o)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question