查看: 7358|回复: 2

LabWindows/CVI调用DLL实用例程(菜农HotPower)

[复制链接]
发表于 2009-4-2 23:57:48 | 显示全部楼层 |阅读模式
关键词: CVI , HotPower , LabWindows , 菜农 , 例程
/*-------------------------------------------------------------------------------------------------------*/
/*    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
#include //需要的API函数实际在winbase.h中定义
#include     /* Needed if linking in external compiler; harmless otherwise */
#include
#include
#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);     
}
/*-------------------------------------------------------------------------------------------------------*/
点击下载工程源码: cvidlldemo.rar
发表于 2009-6-28 23:10:50 | 显示全部楼层
还在用LabWindows/CVI啊,换Labview,不用编代码了
发表于 2010-5-25 22:20:52 | 显示全部楼层
顶一下
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于我们  -  服务条款  -  使用指南  -  站点地图  -  友情链接  -  联系我们
电子工程网 © 版权所有   京ICP备16069177号 | 京公网安备11010502021702
快速回复 返回顶部 返回列表