Valhalla Legends Archive

Programming => General Programming => .NET Platform => Topic started by: Sorc.Polgara on February 11, 2005, 03:21 AM

Title: [C++.NET] Using a .DLL
Post by: Sorc.Polgara on February 11, 2005, 03:21 AM
Um I'm trying to use BnetAuth.dll in my program but I can't seem to figure out how.

I've tried using google, but it doesn't bring up much help because they require these other files with it i.e. ".obj", ".lib"

How the heck am I suppose to use the DLL?
Title: Re: [C++.NET] Using a .DLL
Post by: shout on February 11, 2005, 09:48 AM
I don't know how to do that but because bnetauth.dll is in C++ you could just stick the code in your program. Give credit though if you do.
Title: Re: [C++.NET] Using a .DLL
Post by: K on February 11, 2005, 01:07 PM

// ret_type (* calling_conv pfFunc) (arg_list)
typedef int (*_stdcall pfDllFunc)(int arg1, char* arg2);

HMODULE h = LoadLibrary("mydll.dll");
if (!h)
{
   // error: dll couldn't be loaded or not found.
}

pfDllFunc func = (pfDllFunc)GetProcAddress(h, "FunctionName");
if (!func)
{
   // error: address of function not found in dll
}

int return_value = func(12, "hello");
Title: Re: [C++.NET] Using a .DLL
Post by: Sorc.Polgara on February 11, 2005, 05:19 PM
Quote from: K on February 11, 2005, 01:07 PM

// ret_type (* calling_conv pfFunc) (arg_list)
typedef int (*_stdcall pfDllFunc)(int arg1, char* arg2);

HMODULE h = LoadLibrary("mydll.dll");
if (!h)
{
   // error: dll couldn't be loaded or not found.
}

pfDllFunc func = (pfDllFunc)GetProcAddress(h, "FunctionName");
if (!func)
{
   // error: address of function not found in dll
}

int return_value = func(12, "hello");


okie, it loads the dll fine, but it can't find the address of the function.

this is the function that it can't address, its directly from the header file that declares it:

__declspec(dllexport)
BOOL _stdcall PasswordHash(char *OutBuf, DWORD encryptvalue, char *password);


Here is what I did to address it:

typedef BOOL (*_stdcall PasswordHash)(char *OutBuf, DWORD encryptvalue, char *password);
HMODULE h = LoadLibrary("BnetAuth.dll");

if (!h){
printf("[Error] DLL couldn't be loaded or not found.\n");
}
PasswordHash passhash = (PasswordHash)GetProcAddress(h, "PasswordHash");
if (!passhash){
printf("[Error] Address of function not found in DLL.\n");
}


Title: Re: [C++.NET] Using a .DLL
Post by: K on February 11, 2005, 07:12 PM
is "PasswordHash" the exact name of the function? Did you get the capitalization right? You can check it out using dependancy walker (http://www.dependencywalker.com/) or some other tool.