import VS C++ DLL in C++ Builder

我的未来我决定 提交于 2019-12-13 05:04:19

问题


I created a project using C++/CLI in Visual Studio 2012. The GUI was made in C++ Builder XE2 and I would like to import the generated DLL from VS C++ 2012 but I was not able to import it correctly.

HINSTANCE load = LoadLibrary(library);
if (!load)
    ShowMessage("Error importing the library");

Unfortunately when I run the code after I use the LoadLibrary function the variable load is NULL. Any help?

I unsterstood that I need to use some utilities from the C++ Builder to convert the DLL generated by the Visual Studio into the Borland DLL format.

Edit:

#include "stdafx.h"
#include <windows.h>
#include <iostream>

using namespace cv;
using namespace std;

//Function declarations
__declspec(dllexport) void __stdcall TestCV();

//-------------------------------------------------------------------------------------------------
BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved )
{
    return TRUE;
}
//-------------------------------------------------------------------------------------------------
void __stdcall TestCV()
{
    Mat image;
    image = imread("a.PNG", IMREAD_COLOR); // Read the file

    if(! image.data ) // Check for invalid input
    {
        cout << "Could not open or find the image" << std::endl ;
        return;
    }

    namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display.
    imshow( "Display window", image ); // Show our image inside it.
}
//-------------------------------------------------------------------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{....}

Can anyone help me on how to import that DLL generated by the above source code from Visual Studio C++/CLI into C++ Builder?

Edit2 I did a release build and I copied the DLL project also other DLL files(I use OpenCV). Now I receive the following problem from the C++ Builder project:

Runtime Errror!
Program:

R6033
-Attempt to use MSIL code from this assembly during native code initialization
This indicates a bug in your application. It is most likely the result of  a calling a MSIL-compiled (/dlr) function from a native consturctor or from a DLLMain

来源:https://stackoverflow.com/questions/24723301/import-vs-c-dll-in-c-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!