Redistributable Compiler - DLL for MS Visual Studio

I am programming for my senior project, and I am looking for a compiler that can compile a DLL, which can then be dynamically loaded into a Visual Studio 2008 C ++ application.

The important idea here is that the compiler is redistributable. If VS were redistributable, I would use this.

So far, I have had some success using MinGW, but this success is limited. Currently, I can only load one DLL and work at a time. The moment I try to download the second version, the VS C ++ application crashes with an access violation error.

I managed to load two DLLs compiled into VS without problems, so I am convinced that this is something specific to MinGW, this is a DLL and how they interact with LoadLibrary () and something else.

I have been working on this issue for quite some time, and I am learning. If someone knows about another compiler, which, as you know, will work instead of MinGW, or if you saw this problem, you probably know why the second DLL resets it. I am sure that this is due to the fact that each of the DLLs works on the other in some way, but I have no idea what it will be or how to find out.

It could be a way to compile a DLL or the way I load it; I have no idea.

I would really appreciate feedback, thanks!

Edit: These are simple g ++ and dlltool calls to create a dll http://pastebin.com/f675df4b0

This is the source from one of my dlls. http://pastebin.com/f5c062611

This is the code in my C ++ application for loading a DLL. http://pastebin.com/f52f94a18

-Michael

+4
source share
2 answers

You are returning 0 from DllMain. According to the specifications, you should return TRUE if something fails. However, I do not understand why this should lead to behavior on MSVC or MinGW. He also says that LoadLibrary should return 0 if DllMain returns FALSE, so this may not be the actual explanation.

Is DllMain really called in both MSVC and the MinGW version, does something happen if you delete a comment in a call in it?

For more information about DllMain, select http://msdn.microsoft.com/en-us/library/ms682583(VS.85).aspx

Another thing that might be of interest if you are actually calling AiFunction from the first dll before loading the second. If you do, can you try loading both dll libraries without calling any dll function between them and see if it works better?

My suspicion is that MinGW and MSVC structure input or output structures differently and that for some reason this mismatch of this size leads to some memory corruption when calling AiFunction. You can verify this by comparing the sizeof () results for Output and Input inside and outside the DLL and see if it matches. This does not guarantee that it is correct, but if it does not match, you can be sure that something will go wrong.

Finally, I fear that returning output may be a problem in the long run if you start introducing virtual calls and such things, as this can be implemented in exactly the same way as in MSVC and MinGW. If you store it without virtual functions and such things, this should be fine as long as the packaging structure is consistent.

0
source

Would it be enough to use Visual Studio Express? The compiler is free to download, and it will save you a lot of effort when trying to ensure DLL compatibility.

I don’t know how stringent your requirements are, but the likelihood is that if you check the licensing information for Visual Studio Express, it will be free enough for your project.

+1
source

Source: https://habr.com/ru/post/1301636/


All Articles