-
October 24th, 2005, 04:59 AM
#1
How to link the DLL to ur activex control using LoadLibrary() API call?
hai,
I want to develop activex control. I need to link the DLL to the control using LoadLibrary() API call. Usually LoadLibrary.cpp and LoadLibrary.h these two files are added to the wizard from that we need to call the API LoadLibrary. Its not working now.
Can you explain how to use the LoadLibrary(), getProcAddress() API call in the wizard? What ever modifications i have to do in DLL side?
Thanks in advance,
R.Jaiganesh
-
October 24th, 2005, 05:10 AM
#2
Re: How to link the DLL to ur activex control using LoadLibrary() API call?
I don't understand what you are saying. If you want to use API ::LoadLibrary() and ::GetProcAddress() take a look in MSDN. It's not big deal. You have to do something like this.
Code:
// function prototype from DLL
typedef int (__cdecl myFunc*)(void);
// load the library
HMODULE hdll = ::LoadLibrary("mylib.dll");
if(hdll != NULL)
{
// get a pointer to the desired function
myFunc pointerToMyFunc = (myFunc)::GetProcAddress(hdll, "MyFuncName");
if(pointerToMyFunc != NULL)
{
// call the function
int result = (*pointerToMyFunc)();
}
// free the loaded library
::FreeLibrary(hdll);
}
-
October 24th, 2005, 05:55 AM
#3
Re: How to link the DLL to ur activex control using LoadLibrary() API call?
Look up Run-Time Dynamic Linking - its the kind that interests you.
-
October 25th, 2005, 01:16 AM
#4
Re: How to link the DLL to ur activex control using LoadLibrary() API call?
hai,
How to find out the LoadLibrary ( ) API call is getting executed successfully or Not? how to print the return value of this call? . where to put the DLL ?.I try this LoadLibrary ( ) .It returns MZ string after that it fails in GetProcAddress . can u give sample for this LoadLibrary() and GetProcAddress( )?
Thanks in Advance.
Regards
R.Jaiganesh.
-
October 25th, 2005, 03:42 AM
#5
Re: How to link the DLL to ur activex control using LoadLibrary() API call?
Originally Posted by jaiganeshbe
How to find out the LoadLibrary ( ) API call is getting executed successfully or Not?
See cilu's post.
Originally Posted by jaiganeshbe
how to print the return value of this call? . where to put the DLL ?.
Put the DLL in the application directory, and supply relative path.
Originally Posted by jaiganeshbe
can u give sample for this LoadLibrary() and GetProcAddress( )?
Did you read my previous post? It says "Using DLLs with Sample".
Last edited by Siddhartha; October 25th, 2005 at 03:49 AM.
-
October 25th, 2005, 08:11 AM
#6
Re: How to link the DLL to ur activex control using LoadLibrary() API call?
I cant get address of the function inside the DLL.what ever link specified in that they saying different procedure to build the dll.In my case I already have the DLL.whether I have to change the calling convention of the DLL function or not?
-
October 25th, 2005, 08:42 AM
#7
Re: How to link the DLL to ur activex control using LoadLibrary() API call?
//DLL is having the following API
//DLL name is MyFirstAPIDll.dll
#define MY_API __declspec(dllexport)
MY_API HRESULT MyFirstAPI(char *pApiName)
{
AfxMessageBox("MyFirstAPI");
return S_FALSE;
}
//Now load the This particular dll in the client side applications as follows
UINT uReturnVal;
typedef HRESULT (*typeMyFirstAPI) (char *pApiName);
HINSTANCE hDLL; // Handle to DLL
MySetVarName lpfnDllFunc1; // Function pointer
hDLL = LoadLibrary("MyFirstAPIDll.dll");
if (hDLL != NULL)
{
lpfnDllFunc1 =(typeMyFirstAPI)::GetProcAddress(hDLL,"MyFirstAPI");
if (!lpfnDllFunc1)
{
// handle the error
FreeLibrary(hDLL);
return ;
}
else
{
// call the function
char *pVarname =NULL;
uReturnVal = lpfnDllFunc1(pVarname );
}
}
-
October 25th, 2005, 08:53 AM
#8
Re: How to link the DLL to ur activex control using LoadLibrary() API call?
How to find out the LoadLibrary ( ) API call is getting executed successfully or Not? how to print the return value of this call? . where to put the DLL ?.I try this LoadLibrary ( ) .It returns MZ string after that it fails in GetProcAddress . can u give sample for this LoadLibrary() and GetProcAddress( )?
Do you have MSDN? Then read the documentation of these functions.
-
October 25th, 2005, 08:59 AM
#9
Re: How to link the DLL to ur activex control using LoadLibrary() API call?
Originally Posted by jaiganeshbe
I cant get address of the function inside the DLL.
I think this is the point. First you have to find out the reason of GetProcAddress failure. Did you try to make those dll linking in some test project? just for make yourself sure you understand the things alright?
what ever link specified in that they saying different procedure to build the dll.
Would you say the same but different way? I didn't get your thought.
In my case I already have the DLL.whether I have to change the calling convention of the DLL function or not?
Cool. Never could understand people who make program design by dice throwing. Why do you have to change calling convention? Calling convention of exported function matters for function call but not for its address discovering. To get it you just have to know real export name of the function. And if you don't, then reach for depends.exe and take a look at your dll exports.
Man, I'm really upset. I really cannot understand how anybody can program ActiveX been absolutely faint with dll basics.
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|