开发者

How to use a dll?

开发者 https://www.devze.com 2022-12-12 14:17 出处:网络
I have a .dll file and the .lib file for it. The DLL talks to an electronic key reader, and allows you to read/write the key ID.

I have a .dll file and the .lib file for it.

The DLL talks to an electronic key reader, and allows you to read/write the key ID.

This is the only documentation that comes with:

DLL Usage:
boolean = object.DevicePresent (PROPERTY: true if the device is present)
boolean = object.KeyPresent (PROPERTY: t开发者_运维问答rue if a key is in the device)
long = object.KeyId (PROPERTY: gets the keys id)
object.WriteKeyId KeyId (METHOD: Writes new id to the key)
Private Sub object_KeyRemoved (EVENT: Key removed)

I have never used DLL before and really have no idea how I am supposed to use it in a C program. I really have no idea what do past this:

#include <stdlib.h>
#include <windows.h>

typedef int (__cdecl *MYPROC)(LPWSTR); 
int main(int argc, char *argv[])
{
 HINSTANCE hinstLib; 
 hinstLib = LoadLibrary(TEXT("ekey.dll")); 
 if (hinstLib != NULL) 
 { 
   //now what? how do i get the properties or call a method?
 }
 return 0;
}

If someone could show me an example how how to get DevicePresent and how to use WriteKeyId I would be very greatful!


That documentation suggests that the DLL is an OCX, intended for use with Visual Basic.

Try regsvr32 on it. If that likes it, you can then build the necessary COM API for it from visual studio.

It will be very hard to arrange direct calls to this sort of thing from C, but you can try looking at it with dumpbin and seeing what it exports.

As per the comment, adding a #import for the DLL to your C program is the quickest way forward.


It's a COM DLL. Which makes it practically impossible to use in straight C.


See GetProcAddress(). Ensure the symbol is exported with dumpbin /exports Foo.dll

E.g.

BOOL *pPresent = (BOOL *)GetProcAddress(hInstLib, _T("DevicePresent"));
if (pPresent) {
  printf("%d\n", *pPresent);
}

Caveat You must know the exact data type this object is at the binary level! There is probably a reference somewhere comparing VB <-> Platform SDK Data types.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号