在C ++代码中使用dll

时间:2012-06-29 08:02:06

标签: c++ dll

我想在c ++代码中使用pjsipDll.dll。我从其中一个网站获得了这个dll,我只知道如何构建代码来获取dll文件。所以我这样做了,现在我和我一起提供了pjsipDll.dll文件。我想在我的代码(C ++)中使用DLL中的某些函数

我尝试了以下代码。 <<我没有在项目中创建/添加任何dll或.h文件,只有以下CPP文件>>

#include <iostream>

using namespace std;

int CallMyDLL(void)
{
    /* get handle to dll */
   HINSTANCE hGetProcIDDLL = LoadLibrary("G:\\July\\9.0\\pjsipdll\\Lib\\pjsipDll.dll");

   /* get pointer to the function in the dll*/
   FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"dll_makeCall");

   /*
      Define the Function in the DLL for reuse. This is just prototyping the dll's function.
      A mock of it. Use "stdcall" for maximum compatibility.
   */
   typedef int (__stdcall * pICFUNC)(int, char *);

   pICFUNC MyFunction;
   MyFunction = pICFUNC(lpfnGetProcessID);

   /* The actual call to the function contained in the dll */
   int intMyReturnVal = MyFunction(5,"hello");

   /* Release the Dll */
   FreeLibrary(hGetProcIDDLL);

   /* The return val from the dll */
returnintMyReturnVal;
} 
void main()
{
    cout<<"Hello World";

    CallMyDLL();
    getchar();
}

我从某个站点学到了这种方法,使用DLL中的函数。

问题是,我收到错误:

  

错误C2065:&#39; HINSTANCE&#39; :未声明的标识符g:\ july \ 9.0 \ pjproject-0.9.0 \ myproject \ importerprojet \ importerprojet \ mycpp.cpp 9 importerProjet

任何人都可以帮我解决这个问题。或者如果已经解决了这个问题,至少可以指向我的帖子。

感谢您的帮助, Vinu。

1 个答案:

答案 0 :(得分:6)

您需要#include <windows.h>

相关问题