0

this is my first question here so I'll try to be clear and explain everything I know.

I'm newbie with C++ and I need to create my own dll that use functions from third party dll's, so I want to link one .dll to my proyect and it seems to not work. After having my .dll I have to use it in a C# project using pinvoke.

I've searched everywhere and tried some things but without luck, I have the .h, .lib and .dll and for the moment I have this:

In project properties:

-Set the .lib path in Conf Properties-->Linker-->General-->Additional Library Directory

-Add the .lib name on Conf Properties-->Linker-->Input-->Additional Dependencies

-Set the .dll path in Conf Properties-->C/C++-->General-->Additional inclusion directories

In the project .cpp file

#pragma comment(lib, "HCNetSDK.lib")
#pragma comment(lib, "HCCore.lib")
#include "HCNetSDK.h"

This is the error message:

Error   LNK2019 símbolo externo __imp_NET_DVR_Init sin resolver al que se hace referencia en la función 

I made a small funtion that throws the exception to show up the problem:

.cpp file

#include <stdio.h>
#include "pch.h"
#include <iostream>
#include <string>
#include "Windows.h"
#include "Pruebahikvi.h"
#pragma comment(lib, "HCNetSDK.lib")
#pragma comment(lib, "HCCore.lib")
#include "HCNetSDK.h"
#include <comdef.h>

bool test() {
    bool res = false;
    try {
        //function from HCNetSDK.h
        NET_DVR_Init();
        res = true;
    }
    catch (int ex) {

    }
    return res;
}

.h file

extern "C" __declspec(dllexport) bool test();

AFAIK linking a library dont have to be that hard, hope you guys can help me.

  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Jan 10 '20 at 13:22
  • Can you show your full compiler (link.exe) invocation and confirm that this `__imp_NET_DVR_Init` symbol is present in one of the `.lib` files you link with? – Botje Jan 10 '20 at 13:46
  • Nothing obviously wrong. Maybe you shouldn't do this at all and go straight from C# to this library. [Like this](https://github.com/Frago9876543210/hikvision-bruteforcer/blob/master/web-cam-bruteforcer/CHCNetSDK.cs). Rather evil code btw. – Hans Passant Jan 10 '20 at 13:58
  • @Botje I dont know how to do what you requested but i did a dumpbin of the .lib and [this](https://textsaver.flap.tv/lists/33z7) is what it throws, NET_DVR_Init is on the lib, the "___imp__" prefix is added cause of the "__declspec(dllexport)" – Marcos Chicote Jan 13 '20 at 08:48
  • @KenWhite , Thanks but this post dont answer my question, anyways it explains well how the C++ compile works – Marcos Chicote Jan 13 '20 at 08:50
  • @HansPassant ,I'll give a try at what you have suggested, but I'm supossed to do the way I explained on the question because it is a customer requirement. – Marcos Chicote Jan 13 '20 at 08:53

0 Answers0