Solved

LoadLibrary() from another DLL

Posted on 2003-11-17
7
590 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

920 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