LabWindows/CVI调用DLL实用例程
本例程是在CVI自带的simple添加调用mydll.dll的函数MyDLLCdeclFunction() 网上和CVI的例程很少,一般为调用LIB实例,但很多dll都是以*.dll提供的,故本例程很实用。
本例程主要是调用了三个Windows API函数LoadLibrary(),GetProcAddress(),FreeLibrary()
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 57 2008-05-27 19:53 cvidlldemocvibuild.mydlldependencies.bri
....... 928 2008-05-27 19:53 cvidlldemocvibuild.mydll
esources.res
....... 1127 2011-08-28 22:07 cvidlldemocvibuild.mydlluild.ini
....... 204 2011-08-28 22:08 cvidlldemocvibuild.simpledependencies.bri
....... 298036 2011-08-28 22:08 cvidlldemocvibuild.simple
esources.res
....... 2868586 2011-08-28 22:08 cvidlldemocvibuild.simplesimple.nidobj
....... 7637 2011-08-28 22:09 cvidlldemocvibuild.simpleuild.ini
....... 1361 2006-11-06 10:00 cvidlldemodlluir.h
....... 2216 2006-11-06 10:00 cvidlldemodlluir.uir
....... 2869 2006-11-06 10:00 cvidlldemomydll.c
....... 1213417 2008-05-27 19:53 cvidlldemomydll.cdb
....... 2684 2008-05-27 19:16 cvidlldemomydll.cws
....... 221184 2008-05-27 19:53 cvidlldemomydll.dll
....... 339 2006-11-06 10:00 cvidlldemomydll.h
....... 3368 2008-05-27 19:53 cvidlldemomydll.lib
....... 3724 2006-11-06 10:00 cvidlldemomydll.prj
....... 76 2006-11-06 10:00 cvidlldemo
eadme.txt
....... 3890 2008-05-27 19:39 cvidlldemosimple.c
....... 4773 2008-05-27 23:25 cvidlldemosimple.cws
....... 3899 2008-05-27 19:32 cvidlldemosimple.prj
....... 557056 2011-08-28 22:08 cvidlldemoSIMPLE.exe
....... 3633568 2011-08-28 22:08 cvidlldemoSIMPLE.cdb
....... 3207 2011-08-28 21:12 LabWindowsCVI调用DLL实用例程 .txt
目录 0 2008-05-27 23:20 cvidlldemocvibuild.mydll
目录 0 2008-05-27 23:25 cvidlldemocvibuild.simple
目录 0 2008-05-27 23:26 cvidlldemo
----------- --------- ---------- ----- ----
8834206 26
/* A simple example of using a uir in a dll created both in cvi or an
* external compiler.
*/
/* Include files needed to compile DLL */
#include
#include /* needed if linking DLL in external compiler; harmless otherwise */
#include
#include “dlluir.h“
static long int status = 0;
static int lightVal = 0 panelHandle;
BOOL __stdcall DllMain (HINSTANCE hinstDLL DWORD fdwReason LPVOID lpvReserved)
{
/* The DllMain function is called when ever the DLL is loaded and */
/* unloaded. Place Initialization code for the DLL in this function. */
if (fdwReason == DLL_PROCESS_ATTACH) {
/* Place any initialization which needs to be done when the DLL */
/* is loaded here. */
if (InitCVIRTE (hinstDLL 0 0) == 0) /* needed if linking DLL in external compiler; harmless otherwise */
return 0; /* out of memory */
status = 100;
} else if (fdwReason == DLL_PROCESS_DETACH) {
/* Place any clean-up which needs to be done when the DLL */
/* is unloaded here. */
CloseCVIRTE (); /* needed if linking DLL in external compiler; harmless otherwise */
}
/* return FALSE to abort if initialization fails */
return TRUE;
}
BOOL __stdcall DllEntryPoint (HINSTANCE hinstDLL DWORD fdwReason LPVOID lpvReserved)
{
return DllMain(hinstDLL fdwReason lpvReserved);
}
void DLLEXPORT RunDllUI (void)
{
/* Call this function from the appropriate place in your code */
/* to load and display startup panels. */
panelHandle = LoadPanelEx (0 “dlluir.uir“ PANEL __CVIUserHInst);
DisplayPanel (panelHandle);
RunUserInterface ();
}
int CVICALLBACK CloseUICallback (int panel int control int event
void *callbackData int eventData1 int eventData2)
{
switch (event) {
case EVENT_COMMIT:
HidePanel(panelHandle);
DiscardPanel(panelHandle);
QuitUserInterface(0);
break;
}
return 0;
}
int CVICALLBACK LightSwitchCallback (int panel int control int event
void *callbackData int eventData1 int eventData2)
{
switch (event) {
case EVENT_COMMIT:
GetCtrlVal (panelHandle PANEL_BINARYSWITCH &lightVal);
SetCtrlVal (panelHandle PANEL_LED lightVal);
break;
}
return 0;
}
long int DLLEXPORT __stdcall MyDLLStdcallFunction(LPSTR buffer)
{
MessageBox(NULL buffer “DLL MessageBox called from MyDLLStdcallFunction“ MB_OK);
status = 200;
return (status);
}
long int DLLEXPORT MyDLLCdeclFunction(LPSTR buffer)
{
MessageBox(NULL buffer “DLL MessageBox called from MyDLLCdeclFunction“ MB_OK);
status = 300;
return (status);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 57 2008-05-27 19:53 cvidlldemocvibuild.mydlldependencies.bri
....... 928 2008-05-27 19:53 cvidlldemocvibuild.mydll
esources.res
....... 1127 2011-08-28 22:07 cvidlldemocvibuild.mydlluild.ini
....... 204 2011-08-28 22:08 cvidlldemocvibuild.simpledependencies.bri
....... 298036 2011-08-28 22:08 cvidlldemocvibuild.simple
esources.res
....... 2868586 2011-08-28 22:08 cvidlldemocvibuild.simplesimple.nidobj
....... 7637 2011-08-28 22:09 cvidlldemocvibuild.simpleuild.ini
....... 1361 2006-11-06 10:00 cvidlldemodlluir.h
....... 2216 2006-11-06 10:00 cvidlldemodlluir.uir
....... 2869 2006-11-06 10:00 cvidlldemomydll.c
....... 1213417 2008-05-27 19:53 cvidlldemomydll.cdb
....... 2684 2008-05-27 19:16 cvidlldemomydll.cws
....... 221184 2008-05-27 19:53 cvidlldemomydll.dll
....... 339 2006-11-06 10:00 cvidlldemomydll.h
....... 3368 2008-05-27 19:53 cvidlldemomydll.lib
....... 3724 2006-11-06 10:00 cvidlldemomydll.prj
....... 76 2006-11-06 10:00 cvidlldemo
eadme.txt
....... 3890 2008-05-27 19:39 cvidlldemosimple.c
....... 4773 2008-05-27 23:25 cvidlldemosimple.cws
....... 3899 2008-05-27 19:32 cvidlldemosimple.prj
....... 557056 2011-08-28 22:08 cvidlldemoSIMPLE.exe
....... 3633568 2011-08-28 22:08 cvidlldemoSIMPLE.cdb
....... 3207 2011-08-28 21:12 LabWindowsCVI调用DLL实用例程 .txt
目录 0 2008-05-27 23:20 cvidlldemocvibuild.mydll
目录 0 2008-05-27 23:25 cvidlldemocvibuild.simple
目录 0 2008-05-27 23:26 cvidlldemo
----------- --------- ---------- ----- ----
8834206 26
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)