Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
866 views
in Technique[技术] by (71.8m points)

visual studio 2012 - import VS C++ DLL in C++ Builder

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...