[prev in list] [next in list] [prev in thread] [next in thread]
List: mingw-users
Subject: Re: [Mingw-users] Error exporting a C function to use it in VB6
From: Mario Chacon <the.masch () gmail ! com>
Date: 2009-01-23 10:59:38
Message-ID: 93d66b780901230259j6e2d87cbu1c8cfa4b0a67806a () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
On Wed, Jan 21, 2009 at 12:43 PM, Mario Chacon <the.masch@gmail.com> wrote:
> Thank for update the wiki!..
>
> On Wed, Jan 21, 2009 at 11:34 AM, Xavier Miller <xavier.miller@cauwe.org>wrote:
>
>> You also need to add
>>
>> extern "C"
>>
> Maybe do I need to include __declspec, right ?
>
>
>>
>>
>>
>> Mario Chacon a écrit :
>> > Thank you so much for your fast answer, here it's my declaration:
>> >
>> > #ifndef DLL3_H
>> > #define DLL3_H
>> >
>> > #ifdef DLL3_EXPORTS
>> > #define DLL3_API __declspec(dllexport)
>> > #else
>> > #define DLL3_API __declspec(dllimport)
>> > #endif
>> >
>> >
>> >
>> ///////////////////////////////////////////////////////////////////////////////
>> > // This class is exported from DLL3.dll
>> > class DLL3_API CDLL3
>> > {
>> > public:
>> > CDLL3();
>> > int GetCpuSpeed();
>> > };
>> >
>> > void * __stdcall CreateDll3();
>> > void __stdcall DestroyDll3(void * objptr);
>> > int __stdcall GetCpuSpeedDll3(void * objptr);
>> >
>> > #endif //DLL3_H
>> >
>> > // DLL3.cpp : Defines the entry point for the DLL application.
>> > //
>> >
>> > //#include "stdafx.h"
>> > #define DLL3_EXPORTS
>> > #include "dll.h"
>> > #include <windows.h>
>> >
>> > BOOL APIENTRY DllMain( HANDLE /*hModule*/,
>> > DWORD ul_reason_for_call,
>> > LPVOID /*lpReserved*/
>> > )
>> > {
>> > switch (ul_reason_for_call)
>> > {
>> > case DLL_PROCESS_ATTACH:
>> > case DLL_THREAD_ATTACH:
>> > case DLL_THREAD_DETACH:
>> > case DLL_PROCESS_DETACH:
>> > break;
>> > }
>> > return TRUE;
>> > }
>> > CDLL3::CDLL3()
>> > {
>> > }
>> >
>> > int CDLL3::GetCpuSpeed()
>> > {
>> > // const unsigned __int64 ui64StartCycle = GetCycleCount();
>> > // Sleep(1000);
>> > return 1;;//static_cast<int>((GetCycleCount() - ui64StartCycle) /
>> > 1000000);
>> > }
>> >
>> ///////////////////////////////////////////////////////////////////////////////
>> > // Class wrapper functions
>> >
>> ///////////////////////////////////////////////////////////////////////////////
>> >
>> >
>> ///////////////////////////////////////////////////////////////////////////////
>> > // CreateDLL3 - create an instance of the class CDLL3
>> > void * __stdcall CreateDll3()
>> > {
>> > return new CDLL3;
>> > }
>> >
>> >
>> ///////////////////////////////////////////////////////////////////////////////
>> > // DestroyDLL3 - free the memory for the class instance
>> > void __stdcall DestroyDll3(void * objptr)
>> > {
>> > CDLL3 *dll3 = (CDLL3 *) objptr;
>> > if (dll3)
>> > delete dll3;
>> > }
>> >
>> >
>> ///////////////////////////////////////////////////////////////////////////////
>> > // GetCpuSpeed - returns CPU speed in MHz; for example, ~2193 will be
>> > // returned for a 2.2 GHz CPU.
>> > int __stdcall GetCpuSpeedDll3(void * objptr)
>> > {
>> > CDLL3 *dll3 = (CDLL3 *) objptr;
>> > if (dll3)
>> > return dll3->GetCpuSpeed();
>> > else
>> > return 0;
>> > }
>> >
>> > I will check the pages you give me to me, one again THANK YOU!..
>> >
>> > Salu2...
>> >
>> >
>> > On Wed, Jan 21, 2009 at 11:12 AM, Greg Chicares <
>> gchicares@sbcglobal.net
>> > <mailto:gchicares@sbcglobal.net>> wrote:
>> >
>> > On 2009-01-21 12:44Z, Mario Chacon wrote:
>> > > I'm using devc++ to compile a C++ class and I need to use it from
>> > a "VB6
>> > > application", :(. I'm exporting the function as C with stdcall
>> > but the
>> > > result name it have "bad name", for example a function called
>> > > GetCpuSpeedDll3 in C++ in VB6 it's named
>> _ZN5CDLL311GetCpuSpeedEv.
>> >
>> > That name...
>> > $c++filt __ZN5CDLL311GetCpuSpeedEv
>> > CDLL3::GetCpuSpeed()
>> > ...seems to suggest that this function is defined inside a
>> > C++ class or a C++ namespace, and is not named 'GetCpuSpeedDll3'.
>> > Maybe you should copy and paste the function declaration here.
>> >
>> > > I found this tutorial but it's empty:
>> > > http://www.mingw.org/wiki/Visual_Basic_DLL
>> >
>> > This search:
>> > http://www.google.com/search?q="visual+basic"+dll+mingw
>> > leads to these pages (among others) that might be helpful:
>> > http://osetools.progw.org/index.php/VB-MinGW-DLL
>> > http://wyw.dcweb.cn/stdcall.htm
>> >
>> >
>> ------------------------------------------------------------------------------
>> > This SF.net email is sponsored by:
>> > SourcForge Community
>> > SourceForge wants to tell your story.
>> > http://p.sf.net/sfu/sf-spreadtheword
>> > _______________________________________________
>> > MinGW-users mailing list
>> > MinGW-users@lists.sourceforge.net
>> > <mailto:MinGW-users@lists.sourceforge.net>
>> >
>> > You may change your MinGW Account Options or unsubscribe at:
>> > https://lists.sourceforge.net/lists/listinfo/mingw-users
>> >
>> > _______________________________________________
>> > This list observes the Etiquette found at
>> > http://www.mingw.org/Mailing_Lists.
>> > We ask that you be polite and do the same.
>> >
>> >
>> >
>> > ------------------------------------------------------------------------
>> >
>> >
>> ------------------------------------------------------------------------------
>> > This SF.net email is sponsored by:
>> > SourcForge Community
>> > SourceForge wants to tell your story.
>> > http://p.sf.net/sfu/sf-spreadtheword
>> >
>> >
>> > ------------------------------------------------------------------------
>> >
>> > _______________________________________________
>> > MinGW-users mailing list
>> > MinGW-users@lists.sourceforge.net
>> >
>> > You may change your MinGW Account Options or unsubscribe at:
>> > https://lists.sourceforge.net/lists/listinfo/mingw-users
>> >
>> > _______________________________________________
>> > This list observes the Etiquette found at
>> http://www.mingw.org/Mailing_Lists.
>> > We ask that you be polite and do the same.
>>
>>
>> ------------------------------------------------------------------------------
>> This SF.net email is sponsored by:
>> SourcForge Community
>> SourceForge wants to tell your story.
>> http://p.sf.net/sfu/sf-spreadtheword
>> _______________________________________________
>> MinGW-users mailing list
>> MinGW-users@lists.sourceforge.net
>>
>> You may change your MinGW Account Options or unsubscribe at:
>> https://lists.sourceforge.net/lists/listinfo/mingw-users
>>
>> _______________________________________________
>> This list observes the Etiquette found at
>> http://www.mingw.org/Mailing_Lists.
>> We ask that you be polite and do the same.
>>
>
> Thank you for all men...! It work great!!
[Attachment #5 (text/html)]
<br><br><div class="gmail_quote">On Wed, Jan 21, 2009 at 12:43 PM, Mario Chacon <span \
dir="ltr"><<a href="mailto:the.masch@gmail.com">the.masch@gmail.com</a>></span> \
wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, \
204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Thank for update the \
wiki!..<br><br><div class="gmail_quote"><div class="Ih2E3d">On Wed, Jan 21, 2009 at \
11:34 AM, Xavier Miller <span dir="ltr"><<a href="mailto:xavier.miller@cauwe.org" \
target="_blank">xavier.miller@cauwe.org</a>></span> wrote:<br> <blockquote \
class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt \
0pt 0.8ex; padding-left: 1ex;"> You also need to add<br>
<br>
extern "C"<br>
</blockquote></div><div>Maybe do I need to include __declspec, right \
?<br> </div><div><div></div><div class="Wj3C7c"><blockquote class="gmail_quote" \
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; \
padding-left: 1ex;"> <br>
<br>
<br>
Mario Chacon a écrit :<br>
<div><div></div><div>> Thank you so much for your fast answer, here it's my \
declaration:<br> ><br>
> #ifndef DLL3_H<br>
> #define DLL3_H<br>
><br>
> #ifdef DLL3_EXPORTS<br>
> #define DLL3_API __declspec(dllexport)<br>
> #else<br>
> #define DLL3_API __declspec(dllimport)<br>
> #endif<br>
><br>
><br>
> ///////////////////////////////////////////////////////////////////////////////<br>
> // This class is exported from DLL3.dll<br>
> class DLL3_API CDLL3<br>
> {<br>
> public:<br>
> CDLL3();<br>
> int GetCpuSpeed();<br>
> };<br>
><br>
> void * __stdcall CreateDll3();<br>
> void __stdcall DestroyDll3(void * objptr);<br>
> int __stdcall GetCpuSpeedDll3(void * objptr);<br>
><br>
> #endif //DLL3_H<br>
><br>
> // DLL3.cpp : Defines the entry point for the DLL application.<br>
> //<br>
><br>
> //#include "stdafx.h"<br>
> #define DLL3_EXPORTS<br>
> #include "dll.h"<br>
> #include <windows.h><br>
><br>
> BOOL APIENTRY DllMain( HANDLE /*hModule*/,<br>
> \
DWORD ul_reason_for_call,<br> > \
LPVOID /*lpReserved*/<br> > \
)<br> > {<br>
> switch (ul_reason_for_call)<br>
> {<br>
> case DLL_PROCESS_ATTACH:<br>
> case DLL_THREAD_ATTACH:<br>
> case DLL_THREAD_DETACH:<br>
> case DLL_PROCESS_DETACH:<br>
> break;<br>
> }<br>
> return TRUE;<br>
> }<br>
> CDLL3::CDLL3()<br>
> {<br>
> }<br>
><br>
> int CDLL3::GetCpuSpeed()<br>
> {<br>
> // const unsigned __int64 ui64StartCycle = GetCycleCount();<br>
> // Sleep(1000);<br>
> return 1;;//static_cast<int>((GetCycleCount() - \
ui64StartCycle) /<br> > 1000000);<br>
> }<br>
> ///////////////////////////////////////////////////////////////////////////////<br>
> // Class wrapper functions<br>
> ///////////////////////////////////////////////////////////////////////////////<br>
><br>
> ///////////////////////////////////////////////////////////////////////////////<br>
> // CreateDLL3 - create an instance of the class CDLL3<br>
> void * __stdcall CreateDll3()<br>
> {<br>
> return new CDLL3;<br>
> }<br>
><br>
> ///////////////////////////////////////////////////////////////////////////////<br>
> // DestroyDLL3 - free the memory for the class instance<br>
> void __stdcall DestroyDll3(void * objptr)<br>
> {<br>
> CDLL3 *dll3 = (CDLL3 *) objptr;<br>
> if (dll3)<br>
> delete dll3;<br>
> }<br>
><br>
> ///////////////////////////////////////////////////////////////////////////////<br>
> // GetCpuSpeed - returns CPU speed in MHz; for example, ~2193 will be<br>
> // returned for a 2.2 GHz \
CPU.<br> > int __stdcall GetCpuSpeedDll3(void * objptr)<br>
> {<br>
> CDLL3 *dll3 = (CDLL3 *) objptr;<br>
> if (dll3)<br>
> return dll3->GetCpuSpeed();<br>
> else<br>
> return 0;<br>
> }<br>
><br>
> I will check the pages you give me to me, one again THANK YOU!..<br>
><br>
> Salu2...<br>
><br>
><br>
> On Wed, Jan 21, 2009 at 11:12 AM, Greg Chicares <<a \
href="mailto:gchicares@sbcglobal.net" target="_blank">gchicares@sbcglobal.net</a><br> \
</div></div><div><div></div><div>> <mailto:<a \
href="mailto:gchicares@sbcglobal.net" \
target="_blank">gchicares@sbcglobal.net</a>>> wrote:<br> ><br>
> On 2009-01-21 12:44Z, Mario Chacon wrote:<br>
> > I'm using devc++ to compile a C++ class and I need \
to use it from<br> > a "VB6<br>
> > application", :(. I'm exporting the function \
as C with stdcall<br> > but the<br>
> > result name it have "bad name", for example a \
function called<br> > > GetCpuSpeedDll3 in C++ in VB6 \
it's named _ZN5CDLL311GetCpuSpeedEv.<br> ><br>
> That name...<br>
> $c++filt __ZN5CDLL311GetCpuSpeedEv<br>
> CDLL3::GetCpuSpeed()<br>
> ...seems to suggest that this function is defined inside a<br>
> C++ class or a C++ namespace, and is not named \
'GetCpuSpeedDll3'.<br> > Maybe you should copy and paste the \
function declaration here.<br> ><br>
> > I found this tutorial but it's empty:<br>
> > <a href="http://www.mingw.org/wiki/Visual_Basic_DLL" \
target="_blank">http://www.mingw.org/wiki/Visual_Basic_DLL</a><br> ><br>
> This search:<br>
> <a href="http://www.google.com/search?q=" \
target="_blank">http://www.google.com/search?q=</a>"visual+basic"+dll+mingw<br>
> leads to these pages (among others) that might be helpful:<br>
> <a href="http://osetools.progw.org/index.php/VB-MinGW-DLL" \
target="_blank">http://osetools.progw.org/index.php/VB-MinGW-DLL</a><br> > \
<a href="http://wyw.dcweb.cn/stdcall.htm" \
target="_blank">http://wyw.dcweb.cn/stdcall.htm</a><br> ><br>
> ------------------------------------------------------------------------------<br>
> This SF.net email is sponsored by:<br>
> SourcForge Community<br>
> SourceForge wants to tell your story.<br>
> <a href="http://p.sf.net/sfu/sf-spreadtheword" \
target="_blank">http://p.sf.net/sfu/sf-spreadtheword</a><br> > \
_______________________________________________<br> > MinGW-users \
mailing list<br> > <a \
href="mailto:MinGW-users@lists.sourceforge.net" \
target="_blank">MinGW-users@lists.sourceforge.net</a><br> </div></div>> \
<mailto:<a href="mailto:MinGW-users@lists.sourceforge.net" \
target="_blank">MinGW-users@lists.sourceforge.net</a>><br> <div>><br>
> You may change your MinGW Account Options or unsubscribe at:<br>
> <a href="https://lists.sourceforge.net/lists/listinfo/mingw-users" \
target="_blank">https://lists.sourceforge.net/lists/listinfo/mingw-users</a><br> \
><br> > _______________________________________________<br>
> This list observes the Etiquette found at<br>
> <a href="http://www.mingw.org/Mailing_Lists" \
target="_blank">http://www.mingw.org/Mailing_Lists</a>.<br> > We ask \
that you be polite and do the same.<br> ><br>
><br>
><br>
</div>> ------------------------------------------------------------------------<br>
<div><div></div><div>><br>
> ------------------------------------------------------------------------------<br>
> This SF.net email is sponsored by:<br>
> SourcForge Community<br>
> SourceForge wants to tell your story.<br>
> <a href="http://p.sf.net/sfu/sf-spreadtheword" \
target="_blank">http://p.sf.net/sfu/sf-spreadtheword</a><br> ><br>
><br>
> ------------------------------------------------------------------------<br>
><br>
> _______________________________________________<br>
> MinGW-users mailing list<br>
> <a href="mailto:MinGW-users@lists.sourceforge.net" \
target="_blank">MinGW-users@lists.sourceforge.net</a><br> ><br>
> You may change your MinGW Account Options or unsubscribe at:<br>
> <a href="https://lists.sourceforge.net/lists/listinfo/mingw-users" \
target="_blank">https://lists.sourceforge.net/lists/listinfo/mingw-users</a><br> \
><br> > _______________________________________________<br>
> This list observes the Etiquette found at <a \
href="http://www.mingw.org/Mailing_Lists" \
target="_blank">http://www.mingw.org/Mailing_Lists</a>.<br> > We ask that you be \
polite and do the same.<br> <br>
------------------------------------------------------------------------------<br>
This SF.net email is sponsored by:<br>
SourcForge Community<br>
SourceForge wants to tell your story.<br>
<a href="http://p.sf.net/sfu/sf-spreadtheword" \
target="_blank">http://p.sf.net/sfu/sf-spreadtheword</a><br> \
_______________________________________________<br> MinGW-users mailing list<br>
<a href="mailto:MinGW-users@lists.sourceforge.net" \
target="_blank">MinGW-users@lists.sourceforge.net</a><br> <br>
You may change your MinGW Account Options or unsubscribe at:<br>
<a href="https://lists.sourceforge.net/lists/listinfo/mingw-users" \
target="_blank">https://lists.sourceforge.net/lists/listinfo/mingw-users</a><br> <br>
_______________________________________________<br>
This list observes the Etiquette found at <a \
href="http://www.mingw.org/Mailing_Lists" \
target="_blank">http://www.mingw.org/Mailing_Lists</a>.<br> We ask that you be polite \
and do the same.<br> </div></div></blockquote></div></div></div><br>
</blockquote></div>Thank you for all men...! It work great!!<br>
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
MinGW-users mailing list
MinGW-users@lists.sourceforge.net
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic