?? simple.c
字號:
/*-------------------------------------------------------------------------------------------------------*/
/* LabWindows/CVI調用DLL實用例程(菜農HotPower) */
/* 本例程是在CVI自帶的simple添加調用mydll.dll的函數MyDLLCdeclFunction() */
/* 網上和CVI的例程很少,一般為調用LIB實例,但很多dll都是以*.dll提供的,故本例程很實用。 */
/* 本例程主要是調用了三個Windows API函數LoadLibrary(),GetProcAddress(),FreeLibrary() */
/* 菜農HotPower@126.com 2008.5.27 于西安大雁塔菜地 */
/*-------------------------------------------------------------------------------------------------------*/
/* This is a simple project that will call
* functions from an external DLL */
//#define __cplusplus
#include <stdio.h>
#include <windows.h>//需要的API函數實際在winbase.h中定義
#include <cvirte.h> /* Needed if linking in external compiler; harmless otherwise */
#include <formatio.h>
#include <userint.h>
#include "mydll.h"
/*-------------------------------------------------------------------------------------------------------*/
typedef long int DLLEXPORT (*DLLCdeclFunction)(char *);//定義函數指針
/*-------------------------------------------------------------------------------------------------------*/
int status;
char message[80];
int main (int argc, char *argv[])
{
/*-------------------------------------------------------------------------------------------------------*/
HMODULE hinstLib;
DLLCdeclFunction DLLFunction;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
/*-------------------------------------------------------------------------------------------------------*/
if (InitCVIRTE (0, argv, 0) == 0) /* Needed if linking in external compiler; harmless otherwise */
return -1; /* out of memory */
/* Tell the dll to run it's user interface */
RunDllUI();
/*-------------------------------------------------------------------------------------------------------*/
// Get a handle to the DLL module.
hinstLib = LoadLibrary("mydll.dll");//裝載動態鏈接庫mydll.dll
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)//成功裝載動態鏈接庫mydll.dll
{
DLLFunction = (DLLCdeclFunction)GetProcAddress(hinstLib, (LPCSTR)"MyDLLCdeclFunction");//取函數指針地址
// If the function address is valid, call the function.
if (fRunTimeLinkSuccess = (DLLFunction != NULL))//dll中有函數MyDLLCdeclFunction()
{
Fmt(message, "message via DLL function\n");
status = (long int)DLLFunction (message);//調用dll函數!!!
}
// Free the DLL module
fFreeResult = FreeLibrary(hinstLib);//卸載動態鏈接庫mydll.dll
}
// If unable to call the DLL function, use an alternative
if (! fRunTimeLinkSuccess)
{
Fmt(message, "message via alternative method\n");
MessagePopup ("CVI MessagePopup ", message);
}
/*-------------------------------------------------------------------------------------------------------*/
/* Call the Stdcall Style DLL Function */
status = MyDLLStdcallFunction("Text buffer 1 being passed from CVI to DLL");
/* Display returned value from DLL function */
Fmt(message, "MyDLLStdcallFunction status returned: %i", status);
MessagePopup ("CVI MessagePopup ", message);
/* Call the Cdecl Style DLL Function */
status = MyDLLCdeclFunction("Text buffer 2 being passed from CVI to DLL");
/* Display returned value from DLL function */
Fmt(message, "MyDLLCdeclFunction status returned: %i", status);
MessagePopup ("CVI MessagePopup ", message);
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -