473,394 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Subject: Forcing a .NET obj exposed as COM to use StdCall instead of CdCall

Does anyone know how to force interop to use a stdcall interface on the COM objects it creates instead of the cdcall interface that is standard?

This is very importiant for my project. I need to reference a VB.NET based interop COM object from an outside program. The program will only interact with a stdcall interface on the COM object. .NET interop uses the cdcall interface when it exposes an assembly to COM. I need to figure out how to change this.

Thanks for any help.

-Doug

Jul 21 '05 #1
6 4024
Doug,
.NET interop uses the cdcall interface when it exposes an assembly to COM.


No it doesn't. What makes you think that?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2
I was told that was the case. I could be wrong about that, but it was the explination for why the COM object wasn't working

What type of call does interop use when exposing an assembly to COM

-Dou

BTW, thanks for the info.
Jul 21 '05 #3
Hi,

Thanks for your post.
What type of call does interop use when exposing an assembly to COM?

It's also _stdcall. You can verify it by the following steps:

1. Use Tlbexp.exe (Type Library Exporter) command to generates a type
library that contains definitions of the types defined in the assembly.

Type Library Exporter (Tlbexp.exe)
http://msdn.microsoft.com/library/de...us/cptools/htm
l/cpgrfTypeLibraryExporterTlbExpexe.asp

2. Start the OLE Viewer tool (OLEVIEW.EXE) that shipps with VS .NET.

3. Open the type library in OLE Viewer and you can see that the methods are
declared as _stdcall.

I believe there must be another problem that COM object is not working.
Could you please give us detailed information on the sympton of the problem?

I look forward to hearing from you.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #4
It's not "cdcall". I assume you mean "__cdecl", right?

But in any case, COM works through basically one method, DllGetClassObject.
This is not exported from your .NET interop assembly but from mscoree.dll.
And it's exported through __stdcall from there, as is the standard with
Windows system libraries.

I've never seen a COM client that requires a specific calling convention -
that's one of the things COM is supposed to encapsulate. Otherwise we'd all
still be doing GetProcAddress() and calling function pointers =)

--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"Doug" <do************@pearlinvestments.com> wrote in message
news:A2**********************************@microsof t.com...
Does anyone know how to force interop to use a stdcall interface on the COM objects it creates instead of the cdcall interface that is standard?
This is very importiant for my project. I need to reference a VB.NET based interop COM object from an outside program. The program will only
interact with a stdcall interface on the COM object. .NET interop uses the
cdcall interface when it exposes an assembly to COM. I need to figure out
how to change this.
Thanks for any help.

-Doug

Jul 21 '05 #5
I stand corrected about the stdcall issue. I was repeating that information from the reserch that a person who has a problem similar to mine was doing

I need to make the VB.NET object callable from a program called Trade Station. It is a stock analysis and trading tool that is very importiant to my company. They have a scripting languge called easy language that is built into the system. It is supposed to be capable of extending itself by calling external DLLs. It is very picky about what DLLsit will see though

Others have had success using C++ to write a DLL that will work with Easy Language, but I am hitting a brick wall with VB. I am not a strong C++ programmer, but I am very good at VB. I am hoping to find a way to make interop expose my VB DLL in the same way that the C++ DLL is exposed. Here is a snippet of code that is from a working C++ DLL. I hope it is meaningful. I am not sure :-(

-----------stdafx.h----------
// stdafx.h : include file for standard system include files
// or project specific include files that are used frequently, bu
// are changed infrequentl
/

#pragma onc

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows header
// Windows Header Files
#include <windows.h

// TODO: reference additional headers your program requires her
#define dll_entry( type ) extern"C" type __stdcal

-----------a.cpp----------
// a.cpp : Defines the entry point for the DLL application
/

#include "stdafx.h
#import "c:\Program Files\TradeStation\Program\TSKit.dll" no_namespac
#import "D:\documents\projects\TradeStationInterop\CSharp\ bin\Release\CSharp.tlb

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserve
return TRUE
double __stdcall MyTest(IEasyLanguageObject *pEL, int iNBars

CSharp::_Class1 *com_ptr
CoInitialize(NULL)
CSharp::_Class1Ptr p(__uuidof(CSharp::Class1))
com_ptr = p
double d = com_ptr->TestDouble()

return d
-----------stdafx.cpp----------
// stdafx.cpp : source file that includes just the standard include
// a.pch will be the pre-compiled heade
// stdafx.obj will contain the pre-compiled type informatio

#include "stdafx.h

-----------a.def----------
LIBRARY
EXPORT
MyTest
Jul 21 '05 #6
Doug,

What you're talking about here is a completely different thing than COM.
I've seen these extension scripts in products like Mercator and PoepleSoft.
They basically load a DLL and call a method in it by using GetProcAddress
and a defined signature through a function pointer. However, you will not be
able to pull *that* off with .NET because you cannot create standard exports
in CLR assemblies. You'd need to use C or C++ or (maybe) Delphi. This is not
a problem with COM since the application is not using COM (at least in the
example you describe below).

If the script can call COM objects normally (instead of using
LoadLibrary/GetProcAddress) like, say, VBScript, then it's certainly
possible because .NET can create normal unmanaged COM wrappers around
managed assemblies. But the scenario you describe below is basically
impossible to achieve with plain .NET, COM or not.
--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"Doug" <do************@pearlinvestments.com> wrote in message
news:DA**********************************@microsof t.com...
I stand corrected about the stdcall issue. I was repeating that information from the reserch that a person who has a problem similar to mine
was doing.
I need to make the VB.NET object callable from a program called Trade Station. It is a stock analysis and trading tool that is very importiant to
my company. They have a scripting languge called easy language that is
built into the system. It is supposed to be capable of extending itself by
calling external DLLs. It is very picky about what DLLsit will see though.
Others have had success using C++ to write a DLL that will work with Easy Language, but I am hitting a brick wall with VB. I am not a strong C++
programmer, but I am very good at VB. I am hoping to find a way to make
interop expose my VB DLL in the same way that the C++ DLL is exposed. Here
is a snippet of code that is from a working C++ DLL. I hope it is
meaningful. I am not sure :-(
-----------stdafx.h-----------
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers // Windows Header Files:
#include <windows.h>

// TODO: reference additional headers your program requires here
#define dll_entry( type ) extern"C" type __stdcall
-----------a.cpp-----------
// a.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#import "c:\Program Files\TradeStation\Program\TSKit.dll" no_namespace
#import "D:\documents\projects\TradeStationInterop\CSharp\ bin\Release\CSharp.tlb"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}

double __stdcall MyTest(IEasyLanguageObject *pEL, int iNBars)
{
CSharp::_Class1 *com_ptr;
CoInitialize(NULL);
CSharp::_Class1Ptr p(__uuidof(CSharp::Class1));
com_ptr = p;
double d = com_ptr->TestDouble();

return d;
}

-----------stdafx.cpp-----------
// stdafx.cpp : source file that includes just the standard includes
// a.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

-----------a.def-----------
LIBRARY a
EXPORTS
MyTest

Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: vinu_gt | last post by:
Hi All, I had a question about stdcall and cdecl calling convention related to Visual Studio 6.0 I have a console project and in Project->setting->C++->Code Generation The "calling...
40
by: Neo The One | last post by:
I think C# is forcing us to write more code by enforcing a rule that can be summarized as 'A local variable must be assgined *explicitly* before reading its value.' If you are interested in what...
3
by: Miguel.Herrera | last post by:
I like to create an assembly with a property exposed in COM as bindable. I have tried to use attribute but when I check the typelib produced by regasm for my assembly the property does not have...
12
by: Howard Kaikow | last post by:
In the code below, ALL the lines that start with PPTfile << are getting the following error at build time. "//i:\C++\C++Code\FileOperations\Form1.h(127) : warning C4800: 'System::String __gc *'...
6
by: Doug | last post by:
Does anyone know how to force interop to use a stdcall interface on the COM objects it creates instead of the cdcall interface that is standard? This is very importiant for my project. I need to...
3
by: John Morgan | last post by:
I suppose the answer to this is staring me in the face but.... How do I programmatically get a page to post back? The actual situation is that I am using an aspx table control and changing the...
1
by: Ezmeralda | last post by:
Hello, in some old projects I am using DllImport with its default CallingConvention.StdCall, but the according DLL uses standard _cdecl calling convention. To my understanding this should not...
0
by: Tech quest | last post by:
Hi, I have a C# Class Libarary which is exposed to COM. The issue is base class members are not exposed to COM.As per msdn http://msdn2.microsoft.com/en-us/library/8877bdk6(VS.80).aspx Managed...
6
by: eyald25 | last post by:
I'm having a problem regarding the assembly code with stdcall. "int main(void) { 00F213A0 push ebp 00F213A1 mov ebp,esp 00F213A3 sub esp,0C0h 00F213A9 push ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.