Hi There,

I hope somebody can help me, I work with Visual C++ 2008 with QT libraries

I am trying to include a Interop.Encore.dll file into my program to access our ERP system business objects and post new data to the ERP

We have a Visual Basic program geared to communicate with our ERP using this same DLL file...

Now what is the Syntax for including the neccesary DLL file (no header file available) into my program?

I will also add that I have built my program using a qmake command (compiles headers and source files etc into a sollution file) to include the dll and when I build the solution I get the following:

"1>fatal error C1308: c:\...\Libs\Interop.Encore.dll: linking assemblies is not supported
1>LINK : fatal error LNK1257: code generation failed"

"1>fatal error C1308: c:\...\Libs\Interop.Encore.dll: linking assemblies is not supported
1>LINK : fatal error LNK1257: code generation failed"

Do you have CLR support enabled? Are you gearing your application towards .NET or native code?

You cannot directly link to a DLL like that, as the error says.

To link to a DLL, you can do it either statically or dynamically.

Statically, you need an "import library" (or "interface library"). This is a .lib file that acts as an intermediate between the linker of the compiler suite and the DLL file. Developments suites like MinGW provide tools to generate a .lib file from a DLL. With MinGW, you can use the dlltool program to do that. I don't know about MSVC though, I'm sure there is an equivalent, or that the MinGW dlltool program might produce a .lib file that is compatible with MSVC too.

Anyhow, you have to create the header file manually, and don't forget the extern "C" specification on your function prototypes. You include the header file that you have created for the DLL, and then you link to the .lib file and make sure the DLL is available at run-time for the application (either in the same folder or installed in a standard system folder (usually "C:\Windows\system" or "C:\Windows\system32").


Dynamically, you can use LoadLibrary / GetProcAddress / FreeLibrary (or dlopen / dlsym /dlclose under *nix systems) functions to load the DLL (at run-time), get the function pointers to the functions you have in the DLL, and unload (or free) the library once you are done using the functions of the library (i.e. before exiting the program).

In both cases, you also have to be sure that all the prototypes of your functions (pointers) exactly correspond to the functions in your DLL. That is, same parameters, same return-type, same parameter-types, same ordering of parameters, same calling convention (usually stdcall or cdecl), same name, extern "C", etc.

commented: Perfect explanation +8

Allright guys... due to a deadline and other external factors Ive not been able to test any of this or investigate further

Simply had to write a VB satelite, will maby check back to this when the oppertunity arises, for now I am just going to mark the thread solved to save everyboddy's time, thankyou very much for the quick responses :)

Hi there guys, ok I finally got back to the subject of code while we are re-working the structure (finally)

So I have been looking into the WINAPI LoadLibrary functionality mike mentioned and it looks like it will be ideal, however I have never worked with WINAPI, this might be a REALLY beginner question but how do I include the WINAPI functionality?

Doing some searches I found references to "#include "windows.h"... I found a file "marshal_windows.h" in my visual studio include folder but I am completely lost and I request someone to PLEASE hand me a flashlight here :)

Thanks in advance

Is the DLL a dot net assembly?
If so, add it as a reference.
Of course, you would need to be compiling in /clr mode.
Project->Properties->Add New Reference

Not as far as I am aware, it is a completely external library used for the SysPro ERP system, I attempted to add as reference but failed miserably,

I am however able to add it as a reference in VB.NET and access the functions and classes perfectly so I cannot with certainty say that it is not

I understand. Don't try to add it as a library, though -- just as a reference with /clr turned on...

Enabling /clr I got the following error:

"1>cl : Command line error D8016 : '/EHs' and '/clr' command-line options are incompatible"

After turning off /EHs (C++ Exceptions) I get LOADS of error and warning methods pretaining to QT:

Warning:

static Category QT_FASTCALL category(uint ucs4);

"1>c:\qt\4.5.2\include\qtcore\../../src/corelib/tools/qchar.h(301) : warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall'"

Error:

QVector(int size, const T &t);

"1>c:\qt\4.5.2\include\qtcore\../../src/corelib/tools/qvector.h(112) : error C2182: 't' : illegal use of type 'void'"

Looks like a nightmare

Following Mike's advise I got my program to compile using the information located on the following website:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms686944(v=vs.85).aspx

I do however not know how to access the classes and methods in the library using this, and even if that is necessary,

P.S. I appreciate all the help guys

I think I got a little further:

I managed to import the reference to it after changing the "Additional Library Directories" setting under Linker in C/C++

Now I have the reference imported to my solution, but what do I need to call to get access to its functions in my class?

In VB the code would be:

Imports Encore

what do I need to include in C++?

using namespace Encore;

1>.\Source\Satelite.cpp(6) : error C2871: 'Encore' : a namespace with this name does not exist

No dice :(

Can I see a screen shot of where you made a reference to the DLL in References?
It should look similar to the mock-up I've attached.

Also, is this Adobe Encore or something I can acquire physically?

Interop.Encore.dll used for communicating with Syspro ERP system's business objects

I have a screen shot but no idea how to attach it, can you give me a tip please?

(In the mean time I sent you an email, hope you dont mind)

Got the screenshot. Thanks.
It's has a nested namespace, so the line of code to use it would be:

using namespace Interop::Encore;

Also, if you're using VS 2008 or earlier, you'll be OK, but if you're using VS 2010, you might have a problem when you compile as your dot net version was set at 3.5 when you started the project. Under VS 2010, I've found I need to start all C++ projects under dot net 4.0 (or what ever is highest for the given compiler version). I have not found a way (yet) to modify the dot net version in an existing C++ VS 2010 project without re-creating the project.


On DaniWeb, to include an attachment, you would need to click the "Post Reply" button on the left of the post and you will see the option.

Haha ok got it thnx, anyway, gave that a try, no dice...

Errors:
"1>.\Source\Satelite.cpp(6) : error C2653: 'Interop' : is not a class or namespace name"
"1>.\Source\Satelite.cpp(6) : error C2871: 'Encore' : a namespace with this name does not exist"

The boss man thinks this is becoming a waste of time but my curiosity has been spiked,

any additional assistance would be greatly appreciated

Do you have the /clr switch turned on?
It doesn't look like you're compiling this for dot net.

Also, when you throw the /clr switch (see attachment), you will also need to change the character set from Unicode to MultiByte.

Do you have the /clr switch turned on?
It doesn't look like you're compiling this for dot net.

Please see my 5th post in this thread, I state that I attempted to enable the CLR but could not manage as it was clashing HEAVILY with the QT coding

I understand.
CLR is a requirement if that is a dot net assembly.

When I have had problems mixing different types of libraries, I have found the biggest problem was the character set.

I have found the MultiByte character set switch solves that.

If you switch to MultiByte and are still having problems, we will need to tackle them as they appear.

I understand.
CLR is a requirement if that is a dot net assembly.

When I have had problems mixing different types of libraries, I have found the biggest problem was the character set.

I have found the MultiByte character set switch solves that.

If you switch to MultiByte and are still having problems, we will need to tackle them as they appear.

Alright can you please just guide me on setting that up,

I do the following, set the CLR (attached screenshot)

-> get error because /clr clashes with /ehs

Disable/Change the C++ exceptions (attached screenshot)

-> get 208 errors & 194 warnings... bit unproductive I think :?

Concentrate only on the first error.
It still looks like your character set is "Not Set".

I just converted a project setting /Ehs to yes, turning on /clr and the character set to MultiByte.

I have never mixed anything with the Qt library, but that might not be the problem.

After those settings are made, what is the first error?

Ok first line looks like this:

Coding:

QVector(int size, const T &t);

Error:
"1>c:\qt\4.5.2\include\qtcore\../../src/corelib/tools/qvector.h(112) : error C2182: 't' : illegal use of type 'void'"

I do need to point out that I am NOT able to have EHs set to "Yes"... that clashes with CLR and gives me the error mentioned before

When I turn Ehs OFF I get these errors as I just mentioned here ^

Is that a forward reference?
If so, it's missing a return type.

If it is a line of code, it's missing the actual parameters.

Is that a forward reference?
If so, it's missing a return type.

If it is a line of code, it's missing the actual parameters.

Seems like a declaration taking place in the header file which still needs to be assigned the reference variable...

Under normal circumstances never give a problem, attached screenshot

Ah, it's a constructor.
I'll need to run another test.
Hang on...

OK. I installed Qt (I was curious about it anyway...) and set the include directories to both:
C:\science\QtSDK\Desktop\Qt\4.8.0\msvc2010\include
and
C:\science\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\Qt

and included the #include <qvector.h> and it compiled without error.

Looking at the picture, I see our qvector.h files are slightly different.

QT version 4.5.2 and my coding solution in built using qmake command through command prompt

Dunno if that makes a difference at all...

...and you've set your include directory to the VS20xx directory, right?

If so (and I hate to suggest this):
If you create a new (CLR-based) Hello World project with linking to the Qt library and headers, does it give the same error?

I saw you said "Under normal circumstances..." before, but normal might not have meant CLR. Also, for version 4.5.2, is there a specific VS2008 directory?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.