在C++代码中使用 dll

Using a dll in C++ code

本文关键字:dll C++ 代码      更新时间:2023-10-16

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

我尝试了以下代码。 <<我没有制作/添加任何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:"HINSTANCE":未声明的标识符 g:\july\9.0\pjproject-0.9.0\myproject\importerprojet\importerprojet\mycpp.cpp 9 importerProjet

谁能帮我解决这个问题。或者如果这个查询已经得到解决,至少将我指向帖子。

感谢您的帮助,维努。

你需要#include <windows.h>