创建一个Mingw DLL以与VB EXE一起使用 [英] Create a Mingw DLL to be used with a VB exe

查看:202
本文介绍了创建一个Mingw DLL以与VB EXE一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上找不到适合我的案例的解决方案。我在微软开发者网络,从这里和几个维基的问题,但没有什么,但阅读这么多信息和一些矛盾的人之后...我有一个混乱!

I cannot find any solution in the web that works for my case. I read in Microsoft Developer Network, problems from here and several wikis, but nothing, but after reading so many info and some of the in contradiction to others ... I have a mess!

我的历史记录:

1-我必须更改已在Visual C ++中创建的软件(DLL),并且不知道使用哪个Visual Studio编译它,这个DLL正在使用Visual Basic程序。

1- I have to change a software already created in Visual C++ (a DLL) and I do not know which Visual Studio was used to compile it, this DLL was working with a Visual Basic program.

2-我成功地改变程序使用另一个通讯协议)和我使用Visual Studio 2012,我有一些.NET问题在我的电脑,但我纠正他们,我的电脑应该很好,我调试DLL,并在我的电脑完美的工作,但每当我把DLL的DLL另一个使运行时错误53(没有找到文件),实际上找不到的是MSVCP110D.dll库,我想是因为是一个VS 2012库(编译vc11.0所以看起来像是因为它),所以我决定下一步:

2- I success in changing the program to use another communication protocol (that was the change... easy) and I have used Visual Studio 2012, I had some .NET issues in my computer, but I correct them and my computer should be fine, well I debug the dll and was working perfectly in my computer, but whenever I take the DLL to another makes a Run time error 53 (does not find the file), what actually does not find is the MSVCP110D.dll library, I guess because is a VS 2012 library (compiler vc11.0 so looks like is because of it), so I decide the next step:

3-我决定迁移到Mingw,因为我听说可能创建dll兼容VB exe,确定我安装eclipse和mingw ,并再次修改我的C ++代码以适应Mingw编译器和库,现在我创建的dll,还有.def和库.lib(我重命名扩展名为.a)首先给我一个错误,找不到函数名称,然后我输入:

3- I decide to migrate it to Mingw, because I heard is possible to create dll compatible with VB exe, ok I install eclipse and mingw, and modify again my C++ code to adapt to Mingw compiler and libraries, now I create the dll, also the .def and library .lib (well I rename the extension to .a) first gave me an error that can not find the function name, then I put:

#ifdef __cplusplus
    extern "C" {
#endif

和__stdcall(因为 __ cdecl msvc,我读的),在此更改后运行时错误更改为48(我读这是一个问题加载DLL),我检查是可能是.def的问题,尝试创建一个新的DLL与此.def使用来自VS 2012编译器的lib.exe和DUMPBIN(但它不能正常工作)。

and the __stdcall (because the __cdecl is not for msvc, what I read), after this change the run time error change to 48 (I read this is a problem loading the DLL), I check is could be problem of the .def and try to create a new DLL with this .def usin the lib.exe and DUMPBIN from the VS 2012 compiler (but it does not work properly).

我注释所有内部的函数只返回值0,我删除DllMain有(用于任何程序找到一个入口点初始化),但我评论,因为我不初始化什么,这里我粘贴了一些我的代码。

I comment all inside of my functions to just return the value 0, I remove the DllMain that there was (which is used for any program to find a entry point to initialise) but I commented because I do not initialise nothing, here I paste a bit of my code.

.h:

    #define DLL_TESTER VB // define whenever I use the dll with the VB.exe
    #ifdef DLL_TESTER
        #ifdef DLLTRY_EXPORTS
//after I use the option -DCPDLLEXPORT to define and set the value to __declspec(dllexport)
            #define ADDCALL __declspec(dllexport)
        #else
            #define ADDCALL __declspec(dllimport)
         #endif
         #define DLLTRY __stdcall
//this is supposly the correct one for VB.exe calls but try the __cdecl neither
    #else
//if is not with a VB.exe the tester would be a C application
        #define EXTDLLCALL __cdecl
        #ifdef DLLTRY_EXPORTS
            #define ADDCALL __declspec(dllexport) EXTDLLCALL
        #else
            #define ADDCALL __declspec(dllimport) EXTDLLCALL
        #endif
#endif

可能订单是错误的,但我尝试很多不同的订单,没有工作:
__ declspec(dllexport)之前的返回值(int)与__stdcall和 __ cdecl 旁边或在返回值的另一侧,
前面有 __ stdcall cdecl ...每个订单(因为我看到不同的订单和每个工作) / p>

May the order is wrong, but I try lot of different orders and none working: __declspec(dllexport) before the return value (int) with the __stdcall and __cdecl next to it or in the other side of the return value, in front with __stdcall and cdecl ... every order (because I saw different orders and every worked) but same run time error 48.

#include <string>
#include <Windows.h>

#ifdef __cplusplus
    extern "C" {
#endif

因为有链接问题,如果只是声明它作为一个C ++,所以应该是C正确链接到VB.exe(不同的编译器)

Because there is link problems if is just declare it as a C++, so should be C to be properly linked to VB.exe (different compilers)

我定义了一些枚举和结构,我认为是很好,但我可以也应该导出结构如果在函数调用有这个结构作为参数?,在以前的版本不是...但我创建了一个函数没有

I define then some enums and structures, I think is fine, but may I should also export the struct if in the function call there is this struct as an argument?, in the previous version was not...but I created a function without arguments and does not work neither.

enum ERROR_DLL{ SUCCESS_CP_OK = 0,SUCCESS_CP_CANCELLED = 1}

struct SDllIdentity{
    LPCSTR szID;
    LPCSTR szDeviceID;
}

这就是为什么我包括windows.h,因为在VS2012这是工作我认为它是失败,因为我不使用LPCSTR是一个char *类型,但即使我改变它为char *不起作用。

This is why I include windows.h because in the VS2012 this was working I thought it was failing because I was not using LPCSTR that is a char * type, but even if I change it to char * does not work.

    int __stdcall __declspec(dllexport) InitialiseTerminal(const SDllIdentity* pSDllIdentity, LPCSTR szAddress, int nPort);
//May the order is wrong, but as previously said I tried diferent combinations

    int __stdcall __declspec(dllexport) DisconnectTerminal(const SDllIdentity* pSDllIdentity);
    //ADDCALL int DLLTRY DisconnectTerminal(const SDllIdentity* pSDllIdentity);
    #ifdef __cplusplus
        }
    #endif

.cpp:

#include "dlltry.h"
//then I define some variables and a class, but I don't want to be exported
__stdcall int InitialiseTerminal(const SDllIdentity* pSDllIdentity, LPCSTR szAddress, int nPort) { return 0;}
__stdcall int /*ADDCALL*/ DisconnectTerminal(const SDllIdentity* pSDllIdentity) { return 0; }

我没有包括所有的功能,但是看起来一模一样,我希望我不会忘记一个 ; :S,我在所有这些网站:

I did not include all the functions, but all looks the same, I hope I am not forgeting a ";" :S, I looked in all this sites:

http://www.transmissionzero.co.uk/computing/building-dlls-with-mingw/
http://msdn.microsoft.com/en-us/library/z4zxe9k8.aspx

我试图中止.def,创建libdlltrx.a,所有我读的,
我唯一的下一个解决方案是安装VS2008,因为我认为是编译
一个...但不确定,请阅读,我使它的工作之前
,但因为不兼容,我不能运行它在其他人,我不
想在其他电脑安装任何其他软件。 / p>

I tried to midify .def, create libdlltrx.a, all that I read, my only next solution would be to install VS2008, because I think was compile with that one ... but not sure, please read that I make it work before but because of incompatibilities I can not run it in others and I do not want to install any other software in others PCs.

推荐答案

哇,这是你在那里做的很多不必要的工作。如果要运行使用任何类型的Visual Studio创建的dll,您需要安装可再发行组件在目标系统上的Visual Studio版本。无论您的解决方案有什么问题,得到10步返回并通过安装它们来解决您的原始问题。

Woah, that's a lot of unneccessary work you did there. If you want to run a dll created with any kind of Visual Studio, you need to install the redistributable components of that Visual Studio version on the target system. Whatever problem you have with your "solution", get 10 steps back and fix your original problem by installing them.

这篇关于创建一个Mingw DLL以与VB EXE一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆