我有一个名为DLP Discovery 4000的硬件。它用于投影图像。它可以由用户编程。在硬件的编程指南中,它有一个可以在DLL API接口中访问的函数列表。该指南说这些函数可以通过C ++ / C / Java调用。
我希望能够在C ++程序中使用这些函数来控制电路板。但到目前为止,我正在努力解决如何使用DLL API。
它附带了我安装的软件。该软件具有功能有限的GUI。此外,该软件将名为D4000_usb.dll的文件放在Windows目录中。我如何使用这个.dll文件。
答案 0 :(得分:2)
我发现有人在MSDN
上调用相同的dll 我用一些前缀为// ***
的帮助商评论对其进行了注释,以便为您提供一些指导
#include <windows.h>
#include <stdio.h>
#include <iostream>
typedef int (__cdecl *MYPROC)(LPWSTR);
int main( void )
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// *** This loads the API DLL into you program
// Get a handle to the DLL module.
hinstLib = LoadLibrary(TEXT("D4000_usb.dll"));
// *** Now we check if it loaded ok - ie we should have a handle to it
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
// *** Now we try and get a handle to the function GetNumDev
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "GetNumDev");
// *** Now we check if it that worked
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
// *** Now we call the function with a string parameter
(ProcAdd) (L"Message sent to the DLL function\n");
// *** this is where you need to check if the function call worked
// *** and this where you need to read the manual to see what it returns
}
// *** Now we unload the API dll
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// *** Here is a message to check if the the previous bit worked
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("Message printed from executable\n");
return 0;
}