Vc dll with VB problem

Hi Group

    I have created a dll (win32 dll) my other vc programs can use the dll
without a problem

But i have problem when running a vb app with this dll. It gives "Bad dll
calling convention"

I am sure there is nothing wrong with the parameter .
The the vb compiled exe works ok with the dll, the error only happens during
running in debug mode in vb.

In cpp realm

#ifdef __cplusplus
extern "C" {
#endif

#ifdef MYCPP_API_EXPORTS
#define MYCPP_API __declspec(dllexport)
#else
#define MYCPP_API __declspec(dllimport)
#endif
.............
..........
MYCPP_API  int fnone(void); // this is ok
MYCPP_API  void  fntwo(); // this is ok
MYCPP_API  void  fnthree(int var); // this is not ok

............
...........

#ifdef __cplusplus
};
#endif

In the vb realm
the delcaration at module
Declare Function fnone Lib "Mydll.dll" () As Long
Declare Sub fntwo Lib "Mydll.dll" ()
Declare Sub fnthree Lib "Mydll.dll" (ByVal variable As Integer)' tried as
integer or as long the result is the same!

// at a function
number = fnone()' this is ok
fntwo  'this is ok

fnthree(12)' this gives error during the debug run




any clues ?



--
Regards


0
jamesg (42)
6/5/2004 5:43:31 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
527 Views

Similar Articles

[PageSpeed] 45

Hi There,

[comments inline]

"beauwlf" <jamesg@pd.jaring.my> wrote in message
news:c9t0jf$g1k$1@news4.jaring.my...
> Hi Group
>
>     I have created a dll (win32 dll) my other vc programs can use the dll
> without a problem
>
> But i have problem when running a vb app with this dll. It gives "Bad dll
> calling convention"

VB expects __stdcall calling convention; VC implicitly uses _cdecl by
default. The types are incompatible, as the method for cleaning up the stack
after a function call is not the same between them.

>
> I am sure there is nothing wrong with the parameter .
> The the vb compiled exe works ok with the dll, the error only happens
during
> running in debug mode in vb.
>
> In cpp realm
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
> #ifdef MYCPP_API_EXPORTS
> #define MYCPP_API __declspec(dllexport)
> #else
> #define MYCPP_API __declspec(dllimport)
> #endif
> ............
> .........
> MYCPP_API  int fnone(void); // this is ok
> MYCPP_API  void  fntwo(); // this is ok
> MYCPP_API  void  fnthree(int var); // this is not ok
>
> ...........
> ..........
>
> #ifdef __cplusplus
> };
> #endif
>
> In the vb realm
> the delcaration at module
> Declare Function fnone Lib "Mydll.dll" () As Long
> Declare Sub fntwo Lib "Mydll.dll" ()
> Declare Sub fnthree Lib "Mydll.dll" (ByVal variable As Integer)' tried as
> integer or as long the result is the same!

I would argue that *none* of these are ok :). You might just be getting
lucky that the first two appear to work. In addition to the incompatible
calling convention, VB's Integer type (16 bit) is not the same as a VC
integer (32 bit). You should use the <Long> VB type along with the <long> VC
type.

Try this:
MYCPP_API  __stdcall long fnone(void);
MYCPP_API  __stdcall void  fntwo();
MYCPP_API  __stdcall void  fnthree(long var);

And in VB (the first two are the same as you current declarations):
Declare Function fnone Lib "Mydll.dll" () As Long
Declare Sub fntwo Lib "Mydll.dll" ()
Declare Sub fnthree Lib "Mydll.dll" (ByVal variable As Long)

Regards,
Mike


>
> // at a function
> number = fnone()' this is ok
> fntwo  'this is ok
>
> fnthree(12)' this gives error during the debug run
>
>
>
>
> any clues ?
>
>
>
> --
> Regards
>
>


0
Michael
6/5/2004 6:38:47 PM
Thanks!
Michael
> VB expects __stdcall calling convention; VC implicitly uses _cdecl by
> default. The types are incompatible, as the method for cleaning up the
stack
> after a function call is not the same between them.
So if i use _stdcall is there any drawback to my vc program that uses the
same dll?

Should i compile one with _stdcall for vb app and one with _cdecl for vc app
?




0
jamesg (42)
6/6/2004 3:34:24 PM
MYCPP_API  long _stdcall fnone(void);
 MYCPP_API   void _stdcall   fntwo();
 MYCPP_API  void   _stdcall fnthree(long var);
>
 And in VB (the first two are the same as you current declarations):
 Declare Function fnone Lib "Mydll.dll" () As Long
 Declare Sub fntwo Lib "Mydll.dll" ()
 Declare Sub fnthree Lib "Mydll.dll" (ByVal variable As Long)

 Now i get cant  find dll entry point "the function name" in "dll name"
There is still some incompabilitiy needs to be ironed out for the calling
convention.








0
jamesg (42)
6/7/2004 3:06:39 AM
beauwlf <jamesg@pd.jaring.my> bored us with:

> Thanks!
> Michael
>> VB expects __stdcall calling convention; VC implicitly uses _cdecl by
>> default. The types are incompatible, as the method for cleaning up
>> the stack after a function call is not the same between them.
> So if i use _stdcall is there any drawback to my vc program that uses
> the same dll?
>
> Should i compile one with _stdcall for vb app and one with _cdecl for
> vc app ?

_stdcall will work with VB and VC clients of your DLL.

    WTH


0
spamsucks (94)
6/7/2004 3:41:35 AM
That sounds like you have a name decoration type problem. Did you perhaps
omit the <extern "C"> block in your VC declarations (you showed it in your
original code though)? You might also try opening up your dll with
depends.exe to make sure the functions are actually being exported properly.

Regards,
Mike


"beauwlf" <jamesg@pd.jaring.my> wrote in message
news:ca0lv8$fkr$1@news6.jaring.my...
> MYCPP_API  long _stdcall fnone(void);
>  MYCPP_API   void _stdcall   fntwo();
>  MYCPP_API  void   _stdcall fnthree(long var);
> >
>  And in VB (the first two are the same as you current declarations):
>  Declare Function fnone Lib "Mydll.dll" () As Long
>  Declare Sub fntwo Lib "Mydll.dll" ()
>  Declare Sub fnthree Lib "Mydll.dll" (ByVal variable As Long)
>
>  Now i get cant  find dll entry point "the function name" in "dll name"
> There is still some incompabilitiy needs to be ironed out for the calling
> convention.
>
>
>
>
>
>
>
>


0
Michael
6/7/2004 3:54:52 AM
After making few changes ..

i still get error 49 bad dll call convention from vb..


depends.exe shows correct exported functions..

After checking through the net all the examples directs me to use def file..

that's what I will attempt now. Is there any example for using c++ dll in vb
without using the def file ?

Regards


0
jamesg (42)
6/7/2004 4:11:02 PM
Reply:

Similar Artilces:

mdbperf.dll
Today I' ve installed EXBPA (best practices analyzer /italian version) and I've performed all the tests. I can not resolve an error about MSEXCHANGEIS performance counter (mdbperf.dll). I've read instructions for this and I've enabled the counter using exctrlst.exe. The error doesn't disappear even if I've restarted the service. Before to newly install exchange in repair mode (It's too dangerous !!!) I ask for help. My server is Exchange 2003 Std. SP2 (SBS 2003 Pre SP1) italian version. If I use perfmon.msc I can add all performance counters of MSEXCHANGEIS ! ...

Date Problem !!
hi there i have a big problem with the dates. i enter 09/10/2005 in a cell and it changes to 10/09/2005 !! big problem. it shows 10/09/2005 in the cell but 09/10/2005 in the formula bar !! 2 different dates very confusing is there a way of telling it to use just one kind ??? thanks -- cassy01 ------------------------------------------------------------------------ cassy01's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=780 View this thread: http://www.excelforum.com/showthread.php?threadid=473175 It's the same date, it's just formatted differently o...

Camera Problem
When my mate and I have video call , I can see both my and his picture but he can only see me, own picture missing, if he uses tools, video audio set up he can see himself,, also he had vidio call to family in Australia and that was fine we are both using 2009 14.0.8089s please ...

Problem with Outlook reminders
Whenever I open the outlook (2007), an error message appears which reads: "There was a problem reading one or more reminders. Some reminders may not appear." I ran outlook /cleanreminders at RUN, it opened Outlook but the error message still appeears. How can I fix this problem? OS is windows 7. Jorge Does this happen even if you start Outlook in Safe Mode? (hold down CTRL while you click the icon) See if this helps: http://www.officeforlawyers.com/outlook/tsol.html#safe -- -Ben- Ben M. Schorr, MVP Roland Schorr & Tower http://www.rolandschorr....

Office:mac 2004 installation problem
Hi, I'm wondering if anyone out there can help me... Way back in March I bought a new MacBook, and with it a copy of Office:mac 2004 student & teacher edition. I installed my copy of Office straight away, but didn't realise I needed to uninstall the Trial edition first. Every time I opened anything in Office, both the REAL and TRIAL editions started up - which is obviously quite annoying - so I tried to uninstall the trial. However, the REAL Office then stopped working. Getting a bit fed up, I tried to completely remove all traces of Office and start again. However, when I tr...

Problem with XmlDocument.Load method.
I get an unhandled exception, when I try to execute XmlDocument.Load(...) in my C# Windows application: -------------------------------------------- "Common Language Runtime Debugging Services" Process id... thread id... Click OK to terminate ... Click Cancel to Debug ... -------------------------------------------- Running environment: Windows 2000 Terminal Server, .NET Framework 1.1 with all latest service packs. But strangest thing is - if I run the same programm as an administrator,everything runs well, but if user is power user or User - I get this exception. Even more - I c...

Data Validation problem #5
hi I think that is a different solution entirely - in that example yo gave me it is a simple case of choosing one list and that then sets th range for list 2, however the second set of lists are all individual my requirement is that the validation picks the required items out o just ONE list, whereas in the example you needed to maintain individua lists each of which was dependant on the first selection -- moosife ----------------------------------------------------------------------- moosifer's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1590 View this threa...

WindowProc: combobox messages problem
In my CControlBar I have overridden the virtual WindowProc. The combobox on the controlbar displays correct and behaves well in runtime. Now, I spent a couple of hours trying to get some messages that I need, using WindowProc. This is needed because CControlBar will pass everything on to the controlbar owner, and that's not what I want. WindowProc is my way to intercept those messages. I already found out that the messages are, ehm, weird: their numbers do not match on related defines in winuser.h. To give an example: WM_COMMAND, 0x0003 functions as a WM_SETFOCUS. But WM_SETFOCUS is def...

outlook contact list problem
Hello, I've been using Outlook for quite some time and it worked fine. My set-up: At work an english Outlook 2002 At home a german Outlook 2000 To sync I use an IPAQ PPC with Active Sync 3.7 I've now installed bluetooth support and sync even with my SE mobile phone with XTND Before the contact list was on both computers shown as "first last" i.e. Tom Smith, but now suddenly it shows as "Smith, Tom" I checked the settings on both outlooks and it says: "first last" both in - Tools>Options>Contact options> - Tools > E-mail accounts &g...

Format Painter button problem
When I wish to format several cells the same I double click the format painter and I am able to format each cell without reclicking the button. I have just upgraded to Excel 2003 and now I can only do that on a worksheet that hasn't any VBA code attached. Is this a bug? I know other people on Mr Excel are having the same problem and no one seems to have an answer. Thanks for any response or help you may give me. Skip Depends upon the VBA code attached, I would imagine. If you have worksheet event code that formatted cells, this formatting would overwrite what you painted with the...

Strange Exchange 2003 Pop Problem
If anyone may be able to shed some light on this strange happening I would really appreciate it. I have Exchange Server 2003 running, all of my users can check their email using Outlook/Popping just fine. They also can all go to OWA and check their email fine. I have one user that can use OWA to check her mail, it takes her password, lets her in but if she tries to use Outlook on her desktop it keeps popping up a password error. No matter which station I am at, I can not check email with this account other than using OWA with a web browser. Nothing was changed on the server, I have reset the...

ArrayList memory problem
Hi everyone, I've got the following problem: In my application I make use of two ArrayList objects like this: Public Sub Main() LoadData() End Sub Public Function LoadData() Dim list1 as new ArrayList() [...Fill the arraylist...] AnalyzeData(list1) End Function Public Function AnalyzeData(list1 as ArrayList) Dim list2 as new ArrayList list2 = list1 [...do stuff...] list2.Clear() End Function Now, this code creates a major memory leak....calling GC.Collect() etc. won't help. Can anyone tell me what happens, when I call list2 = list1 - is the whole list co...

Problem when opening Excel 2003 file
How come when I open a file in Excel nothing appears? Yet the same file will open correctly on other peoples computers. Hi try the following: goto 'Tools-Options-General " and uncheck "Ignore other Applications" Exit Excel and try again If this doesn't work try to re-register Excel 1. Close Excel first and 2. On the Windows Taskbar 2.1 Start>Run "excel.exe /unregserver"(no quotes)>OK. 2.2 Start>Run "excel.exe /regserver"(no quotes)>OK. -- Regards Frank Kabel Frankfurt, Germany Bruce Weinstein wrote: > How come when I open a file...

CRM Outlook Client Addin Problem
We have our users installed with the CRM Outlook client. They are running Outlook XP with 256MB ram. In general, they were normally. However, when our users select multiple mail in the Outlook, the client hang up for minutes. Does anybody know the cause and solutions? Hi Gordon, there are several possible causes: 1. Which CRM client are you trying to use: Microsoft CRM Desktop Client for Office Outlook, or Microsoft CRM Laptop Client for Office Outlook? 2. What operating system are the PCs running: Windows 2000 SP2 or Windows XP SP1 or Windows XP SP2? 3. Which service pack of Micro...

Strange problem with some contact names / email senders
Hello! I have a strange Outlook problem which is really annyoing me at the moment! I added someone to my contacts but whenever i reply to their email they're name isn't automatically filled in as it does with other people's email. Also, if i Create a New email message, it never auto-completes their name. (ie if info@babylon-webmaster.fsnet.co.uk is in my contacts under 'Babylon', sends me an email and i reply to it "To: " reads "Babylon <info@babylon- webmaster.fsnet.co.uk>", but for this contact "To:" only ever displays their ...

PivotItem Problem !
Hello, Here is my problem : My macro get data from a dynamic table . For each PivotItems in PivotFields("color"), i get the number or sum in the data range. Everything works well the first time but not after. If a data of one pivotItem is empty, the PivotItem is still on the PivotItemS list on the Table. So my loop "For each" return Error when i use the PivotItem LabelRange function , because there is no column (for ex) for that PivotItem. Is there a way to have only real value one that PivotItems. I try the command PivotCache.Refresh but still the same error. Did i ...

Inbox display problem
My 4 year old got on my computer and now my email is only showing the received column. I would like to have the From and Subject put back in there. Don't know and can't figure out how he did it. Anyone? Frank Frank <anonymous@discussions.microsoft.com> wrote: > My 4 year old got on my computer and now my email is only > showing the received column. I would like to have the > From and Subject put back in there. Don't know and can't > figure out how he did it. Anyone? In addition to what Milly said, you can also reset the current view to its defaul...

Problem with Addresses
I have to input an entire phone book of addresses. I have since manually typed 1175 but this is extremely time consuming and there is no end in site. Luckily, the phone book is posted on a website so I can cut and paste the entires However the entries appear on the website like this: Albis Turlington Architects, LLC Phone: 203-772-1212 175 Orange Street Fax: 203-773-1212 New Haven, CT 06510 when pasted into excel they appear in the same manner, each line in a different cell, phone and fax are in their own cells as well. The formatting ...

Outlook 2003 Problem #4
Hi folks, since I have got Outlook 2003 running, I have got the following problem: I use tow write e-mails offline, and then connect to the internet, and send it all at once. This worked always fine with OE, the written mails I sent away offline were copied into the send folder, and were sent away straght after I connected to the internet. Now I observer the followinf with Outlook 2003: Outlook continues to try to send the e-mail permanently, even if I check the correct checkbox for not participating on send offline. I tried to switch off everything I found, to prevent Outlook to permanently...

Query by Form Problem 06-19-07
I'm using QBF with about six different combo boxes using: [forms]! [formmain]! [combo1] or [forms]![formmain1]![combo1] -like in a VBA book. This is so users can select criteria on a form with the combo boxes, and when they are done, they hit the search button, and it opens up another form based on the query just performed by the combo selection. This worked for about three combo boxes, but when I added another one, it freezes up and opens up a blank page. It's supposed to open the new form based on the query. Is there a better way to do this? I've looked exhaustive...

Problem using Microsoft Web Browser control
I am trying to access the Custom properties of a Web Browser ActiveX control on a form and I keep getting a message telling me that "The Operation on the Microsoft Web Browser object failed. The OLE server may not be registered. To register the OLE server, reinstall it." I searched TechNet and MSDN and could not resolve this. I reinstalled Access 2003 (I have 2003 and 2007 installed on my workstation, XP Pro) and still no resolution. Has anyone else seen this and if so, can you tell me how to resolve this? Jim Does anyone know the name of the file the message...

CopyBeforeWrite missing in VC++ 8 for CString
Hi All, What would be CopyBeforeWrite equivalent fucntion for Cstring in VC 8 tissyrose wrote: > Hi All, > What would be CopyBeforeWrite equivalent fucntion for Cstring in VC 8 Why does CopyBeforeWrite function CString Vc++ 6 removed . When I compile under VS 2005 is says function not found? What would be the possible replace function?>? Many thanks! On 15 Dec 2006 08:36:29 -0800, "tissyrose" <Linson.Tomy@gmail.com> wrote: > >tissyrose wrote: >> Hi All, >> What would be CopyBeforeWrite equivalent fucntion for Cstring in VC 8 > >Why do...

double display in the Watch view with VC++6 sp6
Hi, Since the install of Visual Studio service pack 6 the double display differe in the Watch window of example before (with vc++ sp5) -7701.7701 give in the window -7701.7701 now (with the sp6) in obtain -7701.7700999999997 Thanks Why is this an issue? It strikes me as a bit of concern over an irrelevancy. Floating point isn't accurate anyway, so there is no particular reason to be concerned about trivial differences like this. joe On Wed, 30 Jun 2004 09:39:11 +0200, "Olivier" <olive@nospam.fr> wrote: >Hi, > >Since the install of Visual Studio service ...

Outlook client and a kerberos problem
I install the outlook client and it did not show me any problem but when I open outlook and try to open CRM tap, it shows me an error messages (with no revelevant information - an error ocurred loading Microsoft CRM functionality). At the application log I can see several errors - from two different origins: Origin : MSCRMAddressBook Origin : MSCRMAddIn And at the system log, I see the following error. The kerberos client received a KRB_AP_ERR_MODIFIED error from the server host/crmserver."our domain". This indicates that the password used to encrypt the kerberos service t...

Passing data to DLL problem
Hi, my application uses a callback function in a dll. This function must notify the main application when it is called, through a SendMessage api call. So i've created a global variable in the dll, named parent: HWND parent; LRESULT CALLBACK MyFunction(...........) { ......................... SendMessage(parent, ....................); } in the main application i set the dll variable: HWND * wnd; wnd = (HWND *) GetProcAddress(hinstDLL, "parent"); *wnd = hWnd; this works fine if i use the parent variable it in a normal dll function, but in the callback MyFunction parent resu...