0

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
user558126
  • 1,303
  • 3
  • 21
  • 42
  • 1
    And what does `GetLastError()` return? – PaulMcKenzie Jul 13 '14 at 13:44
  • When I call GetLastError(); nothing happens... – user558126 Jul 13 '14 at 13:47
  • What do you mean "nothing happens"? What is the return value of `GetLastError`? http://msdn.microsoft.com/en-us/library/windows/desktop/ms684175%28v=vs.85%29.aspx Please read the `Return Value` section of that link. You're obviously not following the instructions given when `LoadLibrary` returns NULL. – PaulMcKenzie Jul 13 '14 at 13:48
  • I wrote the following code "int error = GetLastError();" and error == 126 – user558126 Jul 13 '14 at 13:50
  • I am using C++ Builder to load the the Visual Studio C++/CLI Library – user558126 Jul 13 '14 at 13:52
  • Possible duplicate: http://stackoverflow.com/questions/14361992/dll-load-library-error-code-126 Also, your error has nothing to do with Visual Studio or C++ Builder. – PaulMcKenzie Jul 13 '14 at 13:52
  • I wrote more details aboute the VC++ DLL source code – user558126 Jul 13 '14 at 13:58
  • 1
    A failure of LoadLibrary has nothing to do with converting a DLL. You seem to think that `LoadLibrary` does something more than simply attempt to load a DLL into memory. It could be something as simple as the DLL not being found. – PaulMcKenzie Jul 13 '14 at 13:59
  • Did some improvements. I compiled the project using the release mode and I moved my DLL and also all required files to the BC++ Builder release directory. Now I receive R6033 error. – user558126 Jul 13 '14 at 14:22
  • I suggest linking library into your executable and working out any issues. After those issues are resolved, then try LoadLibrary(). – brian beuning Jul 13 '14 at 14:52

0 Answers0