如何从dll调用函数 [英] how to call function from dll

查看:109
本文介绍了如何从dll调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用vc ++和vs2008用c ++编写的abc.dll中调用方法.
我的代码是

 /*  动态库的全局句柄*/
HMODULE g_hLib = NULL;
#if已定义(WIN32)
 #define DERMALOG_LIBNAME"abc.dll"
 /*  加载库*/
   g_hLib = LoadLibrary(DERMALOG_LIBNAME);
   如果(g_hLib == NULL)
   {
      printf(" ,DERMALOG_LIBNAME);

   }
typedef  nRetCode = FC3Initialize(NULL); 


方法原型为DrmErrorCode_t DRMAPI FC3Initialize(const char * szReserved);

它已成功加载,但是当我调用method时,它给出了链接错误...


错误13错误LNK2019:函数公共:void __thiscall CZF1SDKLightTutorialDlg :: OnBnClickedButton3(void)"(?OnBnClickedButton3 @ C​​ZF1SDKLightTutorialDlg @@ QAEXXZ)ZF1SDKLightTutorialDbr中未解决的外部符号_FC3Initialize @ 4被引用.
错误14致命错误LNK1120:1个未解决的外部C:\ Users \ Acer \ Desktop \ a \ ZF1SDKDemo_ZF1SDKDemo \ Debug \ ZF1SDKDemo.exe 1 ZF1SDKLightTutorial

面向初学者的常规DLL导师 [分步:调用C ++ VC ++和VB中的DLL-第1部分 [使用DLL而不导入LIB [ GetProcAddress() [ ^ ]并通过函数指针调用它.


使函数指针指向dll中的函数.
并调用laoddll函数


I want to call method in abc.dll written in c++ using vc++ and vs2008.
My code is

/* global handle for the dynamic library */
HMODULE g_hLib = NULL;
#if defined(WIN32)
    #define DERMALOG_LIBNAME "abc.dll"
/* load the library */
   g_hLib = LoadLibrary(DERMALOG_LIBNAME);
   if (g_hLib==NULL)
   {
      printf("%s not found\n", DERMALOG_LIBNAME);

   }
typedef long nRetCode = FC3Initialize(NULL);


METHOD PROTOTYPE IS DrmErrorCode_t DRMAPI FC3Initialize(const char* szReserved);

It is successfully loaded but when I call method it gives linking error...


Error 13 error LNK2019: unresolved external symbol _FC3Initialize@4 referenced in function "public: void __thiscall CZF1SDKLightTutorialDlg::OnBnClickedButton3(void)" (?OnBnClickedButton3@CZF1SDKLightTutorialDlg@@QAEXXZ) ZF1SDKLightTutorialDlg.obj ZF1SDKLightTutorial

Error 14 fatal error LNK1120: 1 unresolved externals C:\Users\Acer\Desktop\a\ZF1SDKDemo_12July2012_imran\ZF1SDKDemo\ZF1SDKDemo\Debug\ZF1SDKDemo.exe 1 ZF1SDKLightTutorial

解决方案

Take a look at those links here in CP, probably they will help you:

Regular DLL Tutor For Beginners[^]

Step by Step: Calling C++ DLLs from VC++ and VB - Part 1[^]


And this Q&A that seems related to your needs:
using DLL without importing the LIB[^]

Hope this helps...


You cannot make a direct call to a library function unless that library is linked to your program. If you are dynamically loading the DLL at run time then you must use GetProcAddress()[^] and call it through a function pointer.


make function pointer to function in dll.
And call laoddll function


这篇关于如何从dll调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆