473,471 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Call C# COM objects from C++

I wrote a C# class library with tlb output,so i can call it from C++ codes.

My code in C# like:

[Guid("...")]
public struct item
{
string key;
double val;
}

[Guid("...")]
public interface IFirst
{
string try();
item[] tryAgain();
}

[Guid("...")]
public class First : IFirst
{
public string try(){...}
public item[] tryAgain(){...}
}

My code in C++ like:

IFirstPtr p;
p.CreateInstance(__uuidof(First));
_bstr_t bt = p->try();
SAFEARRAY* psa = p->tryAgain();

Well,my problem is here:
the p->try() call is processed OK,and i got the correct return values.
while the p->tryAgain() call failed,as i debugged into the .tli code
generated by IDE,
i found the HRESULT code of the raw_tryAgain() call is 0X80028019,says "old
format or invalid type library",which i thought meant nothing to me.

So,could anybody help me?
I am using VS.Net 2003.

Whyithappen

Nov 16 '05 #1
1 2723
Whyithappen,

I would try removing the Guid attribute from the struct, as I don't
think you need it.

Also, are you strong naming your assemblies, as well as placing the Guid
attribute on the assembly level?

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Whyithappen" <Wh*********@discussions.microsoft.com> wrote in message
news:B3**********************************@microsof t.com...
I wrote a C# class library with tlb output,so i can call it from C++ codes.

My code in C# like:

[Guid("...")]
public struct item
{
string key;
double val;
}

[Guid("...")]
public interface IFirst
{
string try();
item[] tryAgain();
}

[Guid("...")]
public class First : IFirst
{
public string try(){...}
public item[] tryAgain(){...}
}

My code in C++ like:

IFirstPtr p;
p.CreateInstance(__uuidof(First));
_bstr_t bt = p->try();
SAFEARRAY* psa = p->tryAgain();

Well,my problem is here:
the p->try() call is processed OK,and i got the correct return values.
while the p->tryAgain() call failed,as i debugged into the .tli code
generated by IDE,
i found the HRESULT code of the raw_tryAgain() call is 0X80028019,says
"old
format or invalid type library",which i thought meant nothing to me.

So,could anybody help me?
I am using VS.Net 2003.

Whyithappen

Nov 16 '05 #2

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

Similar topics

5
by: Mario Thiel | last post by:
Hello, i am new to JavaScript and right now i am learning Call by Value. i tryed to write a small script but somehow it doesnt work right. i cant put <br> into it, and i can only put the...
23
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
8
by: trying_to_learn | last post by:
Why do we need to explicitly call the copy constructor and the operator = , for base class and member objects in composition? ....book says "You must explicitly call the GameBoard copy-constructor...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
24
by: Jazper | last post by:
hi i have this problem. i made a class deverted by CRootItem with implementation of IDisposable-Interface. i made a test-funktion to test my Dispose-Method.... but when set a breakpoint in my...
5
by: GCRhoads | last post by:
I have some templated functions and I want to write a call wrapper class for it. I also want to pass the function object from this class to some functions that will then call the function...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
4
by: Frank Lund | last post by:
Should we call .Dispose() every chance we get... on every object that exposes .Dispose()... and every time we have such an object? For example, is it true that *every* time I create a DataTable...
44
by: Steven D'Aprano | last post by:
I have a class which is not intended to be instantiated. Instead of using the class to creating an instance and then operate on it, I use the class directly, with classmethods. Essentially, the...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.