Solved

LoadLibrary() from another DLL

Posted on 2003-11-17
7
600 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
is twain_32.dll cmpatible with windows 10 ? 10 267
Android development question 2 104
Outlook 13 98
Creating a Windows C++ program in visual studio 2015 5 24
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

739 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