0

I build my DLL in debug mode, for window x86 system. Here is it's code

#include "pch.h"
#include <windows.h>
#include <iostream>
//I want my client app can use function nhan_2 and nhan_4
extern "C" __declspec(dllexport) int nhan_2(int a) {
    return a * 2;
}

extern "C" __declspec(dllexport) int nhan_4(int a) {
    return a * 4;
}

The output DLL was called Dll.dll, The output lib was called Dll.lib. Both was put in "D:\OLD C DRIVE\source\repos\Dll\Debug".

Then I created another project in debug mode, window x86 system. Here is it's code:

#include<iostream>
using namespace std;
#pragma comment (lib, "Dll.lib")
int main() {
    int b = nhan_2(3);
    cout << "b equal: " << b << endl;
 }

Visual studio keep saying that identifier "nhan_2" is undefined and not found, even though I already config my project properties as:

  1. VC++ Directories->Include Directories: D:\OLD C DRIVE\source\repos\Dll\Debug
  2. VC++ Directories->External Include Directories: D:\OLD C DRIVE\source\repos\Dll\Debug
  3. VC++ Directories->Library Directories: D:\OLD C DRIVE\source\repos\Dll\Debug
  4. C/C++-> General->Additional Include Directories: D:\OLD C DRIVE\source\repos\Dll\Debug
  5. Linker -> General->Additional Library Directories: D:\OLD C DRIVE\source\repos\Dll\Debug
  6. Linker -> Input-> Additional Dependencies: Dll.lib
  7. Linker -> System -> SubSytem: Console
  8. Build Events -> Post-Build Event-> Command Line: xcopy /y /d "D:\OLD C DRIVE\source\repos\Dll\Debug\Dll.dll" "$(OutDir)"

Can some one help me use my DLL ?

tu nguyen
  • 13
  • 2
  • You also need a header file to define function prototypes, that must be included by your main source file. A couple of examples on how to do it: https://stackoverflow.com/a/34777349/4788546, https://stackoverflow.com/a/73506217/4788546, https://stackoverflow.com/a/30583411/4788546, https://stackoverflow.com/a/44469099/4788546, https://stackoverflow.com/a/47551640/4788546, https://stackoverflow.com/a/54298299/4788546. – CristiFati Aug 17 '23 at 06:12
  • 1
    Thank you. I added the same header file of my DLL to my project’s folder, and then #include it. And it worked ! – tu nguyen Aug 25 '23 at 04:00

0 Answers0