Solved

LoadLibrary() from another DLL

Posted on 2003-11-17
7
588 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 150 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 100 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now