[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">&lt;<a href="mailto:the.masch@gmail.com">the.masch@gmail.com</a>&gt;</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">&lt;<a href="mailto:xavier.miller@cauwe.org" \
target="_blank">xavier.miller@cauwe.org</a>&gt;</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>
 &nbsp; &nbsp; &nbsp; &nbsp;extern &quot;C&quot;<br>
</blockquote></div><div>Maybe do I need to include __declspec, right \
?<br>&nbsp;</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>&gt; Thank you so much for your fast answer, here it&#39;s my \
declaration:<br> &gt;<br>
&gt; #ifndef DLL3_H<br>
&gt; #define DLL3_H<br>
&gt;<br>
&gt; #ifdef DLL3_EXPORTS<br>
&gt; &nbsp; &nbsp; #define DLL3_API __declspec(dllexport)<br>
&gt; #else<br>
&gt; &nbsp; &nbsp; #define DLL3_API __declspec(dllimport)<br>
&gt; #endif<br>
&gt;<br>
&gt;<br>
&gt; ///////////////////////////////////////////////////////////////////////////////<br>
 &gt; // This class is exported from DLL3.dll<br>
&gt; class DLL3_API CDLL3<br>
&gt; {<br>
&gt; public:<br>
&gt; &nbsp; &nbsp; CDLL3();<br>
&gt; &nbsp; &nbsp; int GetCpuSpeed();<br>
&gt; };<br>
&gt;<br>
&gt; void * __stdcall CreateDll3();<br>
&gt; void __stdcall DestroyDll3(void * objptr);<br>
&gt; int __stdcall GetCpuSpeedDll3(void * objptr);<br>
&gt;<br>
&gt; #endif //DLL3_H<br>
&gt;<br>
&gt; // DLL3.cpp : Defines the entry point for the DLL application.<br>
&gt; //<br>
&gt;<br>
&gt; //#include &quot;stdafx.h&quot;<br>
&gt; #define DLL3_EXPORTS<br>
&gt; #include &quot;dll.h&quot;<br>
&gt; #include &lt;windows.h&gt;<br>
&gt;<br>
&gt; BOOL APIENTRY DllMain( HANDLE /*hModule*/,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp;DWORD &nbsp;ul_reason_for_call,<br> &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LPVOID /*lpReserved*/<br> &gt; &nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;)<br> &gt; {<br>
&gt; &nbsp; &nbsp; switch (ul_reason_for_call)<br>
&gt; &nbsp; &nbsp; {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; case DLL_PROCESS_ATTACH:<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; case DLL_THREAD_ATTACH:<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; case DLL_THREAD_DETACH:<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; case DLL_PROCESS_DETACH:<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br>
&gt; &nbsp; &nbsp; }<br>
&gt; &nbsp; &nbsp; return TRUE;<br>
&gt; }<br>
&gt; CDLL3::CDLL3()<br>
&gt; {<br>
&gt; }<br>
&gt;<br>
&gt; int CDLL3::GetCpuSpeed()<br>
&gt; {<br>
&gt; // &nbsp; &nbsp;const unsigned __int64 ui64StartCycle = GetCycleCount();<br>
&gt; // &nbsp; &nbsp;Sleep(1000);<br>
&gt; &nbsp; &nbsp; return 1;;//static_cast&lt;int&gt;((GetCycleCount() - \
ui64StartCycle) /<br> &gt; 1000000);<br>
&gt; }<br>
&gt; ///////////////////////////////////////////////////////////////////////////////<br>
 &gt; // Class wrapper functions<br>
&gt; ///////////////////////////////////////////////////////////////////////////////<br>
 &gt;<br>
&gt; ///////////////////////////////////////////////////////////////////////////////<br>
 &gt; // CreateDLL3 - create an instance of the class CDLL3<br>
&gt; void * __stdcall CreateDll3()<br>
&gt; {<br>
&gt; &nbsp; &nbsp; return new CDLL3;<br>
&gt; }<br>
&gt;<br>
&gt; ///////////////////////////////////////////////////////////////////////////////<br>
 &gt; // DestroyDLL3 - free the memory for the class instance<br>
&gt; void __stdcall DestroyDll3(void * objptr)<br>
&gt; {<br>
&gt; &nbsp; &nbsp; CDLL3 *dll3 = (CDLL3 *) objptr;<br>
&gt; &nbsp; &nbsp; if (dll3)<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; delete dll3;<br>
&gt; }<br>
&gt;<br>
&gt; ///////////////////////////////////////////////////////////////////////////////<br>
 &gt; // GetCpuSpeed - returns CPU speed in MHz; &nbsp;for example, ~2193 will be<br>
&gt; // &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returned for a 2.2 GHz \
CPU.<br> &gt; int __stdcall GetCpuSpeedDll3(void * objptr)<br>
&gt; {<br>
&gt; &nbsp; &nbsp; CDLL3 *dll3 = (CDLL3 *) objptr;<br>
&gt; &nbsp; &nbsp; if (dll3)<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; return dll3-&gt;GetCpuSpeed();<br>
&gt; &nbsp; &nbsp; else<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; return 0;<br>
&gt; }<br>
&gt;<br>
&gt; I will check the pages you give me to me, one again THANK YOU!..<br>
&gt;<br>
&gt; Salu2...<br>
&gt;<br>
&gt;<br>
&gt; On Wed, Jan 21, 2009 at 11:12 AM, Greg Chicares &lt;<a \
href="mailto:gchicares@sbcglobal.net" target="_blank">gchicares@sbcglobal.net</a><br> \
</div></div><div><div></div><div>&gt; &lt;mailto:<a \
href="mailto:gchicares@sbcglobal.net" \
target="_blank">gchicares@sbcglobal.net</a>&gt;&gt; wrote:<br> &gt;<br>
&gt; &nbsp; &nbsp; On 2009-01-21 12:44Z, Mario Chacon wrote:<br>
&gt; &nbsp; &nbsp; &nbsp;&gt; I&#39;m using devc++ to compile a C++ class and I need \
to use it from<br> &gt; &nbsp; &nbsp; a &quot;VB6<br>
&gt; &nbsp; &nbsp; &nbsp;&gt; application&quot;, :(. I&#39;m exporting the function \
as C with stdcall<br> &gt; &nbsp; &nbsp; but the<br>
&gt; &nbsp; &nbsp; &nbsp;&gt; result name it have &quot;bad name&quot;, for example a \
function called<br> &gt; &nbsp; &nbsp; &nbsp;&gt; GetCpuSpeedDll3 in C++ in VB6 \
it&#39;s named _ZN5CDLL311GetCpuSpeedEv.<br> &gt;<br>
&gt; &nbsp; &nbsp; That name...<br>
&gt; &nbsp; &nbsp; &nbsp;$c++filt __ZN5CDLL311GetCpuSpeedEv<br>
&gt; &nbsp; &nbsp; &nbsp;CDLL3::GetCpuSpeed()<br>
&gt; &nbsp; &nbsp; ...seems to suggest that this function is defined inside a<br>
&gt; &nbsp; &nbsp; C++ class or a C++ namespace, and is not named \
&#39;GetCpuSpeedDll3&#39;.<br> &gt; &nbsp; &nbsp; Maybe you should copy and paste the \
function declaration here.<br> &gt;<br>
&gt; &nbsp; &nbsp; &nbsp;&gt; I found this tutorial but it&#39;s empty:<br>
&gt; &nbsp; &nbsp; &nbsp;&gt; <a href="http://www.mingw.org/wiki/Visual_Basic_DLL" \
target="_blank">http://www.mingw.org/wiki/Visual_Basic_DLL</a><br> &gt;<br>
&gt; &nbsp; &nbsp; This search:<br>
&gt; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?q=" \
target="_blank">http://www.google.com/search?q=</a>&quot;visual+basic&quot;+dll+mingw<br>
 &gt; &nbsp; &nbsp; leads to these pages (among others) that might be helpful:<br>
&gt; &nbsp; &nbsp; &nbsp;<a href="http://osetools.progw.org/index.php/VB-MinGW-DLL" \
target="_blank">http://osetools.progw.org/index.php/VB-MinGW-DLL</a><br> &gt; &nbsp; \
&nbsp; &nbsp;<a href="http://wyw.dcweb.cn/stdcall.htm" \
target="_blank">http://wyw.dcweb.cn/stdcall.htm</a><br> &gt;<br>
&gt; &nbsp; &nbsp; ------------------------------------------------------------------------------<br>
 &gt; &nbsp; &nbsp; This SF.net email is sponsored by:<br>
&gt; &nbsp; &nbsp; SourcForge Community<br>
&gt; &nbsp; &nbsp; SourceForge wants to tell your story.<br>
&gt; &nbsp; &nbsp; <a href="http://p.sf.net/sfu/sf-spreadtheword" \
target="_blank">http://p.sf.net/sfu/sf-spreadtheword</a><br> &gt; &nbsp; &nbsp; \
_______________________________________________<br> &gt; &nbsp; &nbsp; MinGW-users \
mailing list<br> &gt; &nbsp; &nbsp; <a \
href="mailto:MinGW-users@lists.sourceforge.net" \
target="_blank">MinGW-users@lists.sourceforge.net</a><br> </div></div>&gt; &nbsp; \
&nbsp; &lt;mailto:<a href="mailto:MinGW-users@lists.sourceforge.net" \
target="_blank">MinGW-users@lists.sourceforge.net</a>&gt;<br> <div>&gt;<br>
&gt; &nbsp; &nbsp; You may change your MinGW Account Options or unsubscribe at:<br>
&gt; &nbsp; &nbsp; <a href="https://lists.sourceforge.net/lists/listinfo/mingw-users" \
target="_blank">https://lists.sourceforge.net/lists/listinfo/mingw-users</a><br> \
&gt;<br> &gt; &nbsp; &nbsp; _______________________________________________<br>
&gt; &nbsp; &nbsp; This list observes the Etiquette found at<br>
&gt; &nbsp; &nbsp; <a href="http://www.mingw.org/Mailing_Lists" \
target="_blank">http://www.mingw.org/Mailing_Lists</a>.<br> &gt; &nbsp; &nbsp; We ask \
that you be polite and do the same.<br> &gt;<br>
&gt;<br>
&gt;<br>
</div>&gt; ------------------------------------------------------------------------<br>
 <div><div></div><div>&gt;<br>
&gt; ------------------------------------------------------------------------------<br>
 &gt; This SF.net email is sponsored by:<br>
&gt; SourcForge Community<br>
&gt; SourceForge wants to tell your story.<br>
&gt; <a href="http://p.sf.net/sfu/sf-spreadtheword" \
target="_blank">http://p.sf.net/sfu/sf-spreadtheword</a><br> &gt;<br>
&gt;<br>
&gt; ------------------------------------------------------------------------<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; MinGW-users mailing list<br>
&gt; <a href="mailto:MinGW-users@lists.sourceforge.net" \
target="_blank">MinGW-users@lists.sourceforge.net</a><br> &gt;<br>
&gt; You may change your MinGW Account Options or unsubscribe at:<br>
&gt; <a href="https://lists.sourceforge.net/lists/listinfo/mingw-users" \
target="_blank">https://lists.sourceforge.net/lists/listinfo/mingw-users</a><br> \
&gt;<br> &gt; _______________________________________________<br>
&gt; 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> &gt; 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