C# app with COM Interface for array of COM structs

S

Sharon G.

I can not attach the USDA.dll even if I using it in a RAR file sized 85,361 bytes.

I'm getting the error:
Outlook Express could not post your message. Subject 'Re: C# app with COM Interface for array of COM structs', Account: 'msnews.microsoft.com', Server: 'msnews.microsoft.com', Protocol: NNTP, Server Response: '437 (648) Transfer Failed - Do Not Try Again -- The Article is too large', Port: 119, Secure(SSL): No, Server Error: 437, Error Number: 0x800CCCA9
 
W

Willy Denoyette [MVP]

Sharon said:
Actually I'm not looking directly to the tlb file.
In the VB client I'm simply marking name that matches the tlb file (which
is
the same name as the C# exe file but with the tlb extension instead of the
exe) in the References list.

Also when using the oleview to look for the C# COM exposure - I see that
the
struct like it's defined in there in spite the fact that this struct is
defined in the native COM DLL.

My guess that something is wrong in the native COM dll USDA.dll that
whenever I'm referencing it in the C# project its struct get like defined
in
the C# tlb.
It does not happen in the activeX test we made.

Maybe there a way to generate the interop (using the TlbImp.exe) for the
USDA.dll so its struct will nor get defined in the C# tlb?


I keep saying that using oleview on your C# tlb file should include
importlib directives.
these directives are needed to unclude the typelib definitions from other
typelibs needed.

So oleview on your C# tlb should look like this:


// TLib : // TLib : : {8F0A80A1-1351-42CA-9B18-CDB349102B29}
importlib("USDA.tlb");
// TLib : mscorlib.dll : {BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}
importlib("mscorlib.tlb");
// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");

here, stdole2.tlb is imported because it's needed by COM itself, this tlb is
imported in every COM typelib, mscorlib.tlb import is needed for
managed/native COM interop, and finally your native COM tlb (or dll) must be
imported to get at the definition of the structure.

If you don't see these importlib's, then or, there is something wrong, or,
you are using an old and buggy OLEVIEW. I would suggest you try using
oleview from VS2008 (see common7\tools\bin) or from the latest platform sdk.


Willy.
 
W

Willy Denoyette [MVP]

I can not attach the USDA.dll even if I using it in a RAR file sized 85,361 bytes.

I'm getting the error:
Outlook Express could not post your message. Subject 'Re: C# app with COM Interface for array of COM structs', Account: 'msnews.microsoft.com', Server: 'msnews.microsoft.com', Protocol: NNTP, Server Response: '437 (648) Transfer Failed - Do Not Try Again -- The Article is too large', Port: 119, Secure(SSL): No, Server Error: 437, Error Number: 0x800CCCA9




No need to send the project, it makes no sense, I'm not going to install W2K with an outdated version of VC6 to get this running in a similar context as yours, sorry.

Willy.
 
S

Sharon

I'm using the oleview version 2.1.0.60 of the VS2005.

I do see the importlib directives, but the importlib for the usda.dll is
missing.
Here is the importlib directive at the sample project that does work for the
MyTest.dll native COM dll (the activX test we made) but does not work for the
USDA.dll native com dll (the problematic dll):

// TLib : // TLib : mscorlib.dll : {BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}
importlib("mscorlib.tlb");
// TLib : : {EA3AA151-7E8A-4BD8-B96F-54EAC73BE40A}
importlib("MyTest.dll");
// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");

I guess this is the reason, why the definition of the struct is at the C# tlb.
Is there a way to prevent that?


P.S.: I do think you can use the sample project. You don't need Win200, you
can use the native COM DLL's and to reference them from within the VS2005.
This way you will be able to see everything that should and does not work.
 
S

Sharon G.

Due ro the suspicion we had about the USDA.dll (the native COM dll). I have compiled it on the VS2005 on WinXP+SP2, and the results are the same.

PECULIAR...
 
W

Willy Denoyette [MVP]

Due ro the suspicion we had about the USDA.dll (the native COM dll). I have compiled it on the VS2005 on WinXP+SP2, and the results are the same.

PECULIAR...



-------
Thaks
Sharon


I would't directly assume something is wrong with this USDA.dll, IMO there is something wrong with the way you are importing the USDA typelib.

Make sure that:
- the USDA.dll is registered (regsvr32.exe) and check it's apartment requirements, it should be "apartment" or "both".
- no older versions of both, the native component and the csharp assembly (or exe) remain registered, before you try this in sequence.

1. tlbimp usda.tlb /out:usda.interop.dll
2. set a reference to usda.interop.dll when compiling the C# code, for instance using
csc /r:usda.interop.dll xxxxxxx.cs
form the command-line.
3. run regasm /tlb /codebase xxxxxxx.dll
4. in VB6, reset the references to xxxxxx.tlb and usda.tlb and rebuild build the VB6 client
Run your client and inspect the xxxxx.tlb using oleview.

Willy.
 
S

Sharon

I did all that but still the same.

In the registry I found the USDA is registered as:

[HKEY_CLASSES_ROOT\CLSID\{45C5732A-9C24-11D3-9EEE-0090278B204C}]
@="USDAObject Class"

[HKEY_CLASSES_ROOT\CLSID\{45C5732A-9C24-11D3-9EEE-0090278B204C}\InprocServer32]
@="D:\\Sharon's\\Rubbish\\COM-.NET Struct\\COM Objects\\USDA.dll"
"ThreadingModel"="Single"

[HKEY_CLASSES_ROOT\CLSID\{45C5732A-9C24-11D3-9EEE-0090278B204C}\ProgID]
@="USDA.USDAObject.1"

[HKEY_CLASSES_ROOT\CLSID\{45C5732A-9C24-11D3-9EEE-0090278B204C}\Programmable]

[HKEY_CLASSES_ROOT\CLSID\{45C5732A-9C24-11D3-9EEE-0090278B204C}\TypeLib]
@="{45C5731B-9C24-11D3-9EEE-0090278B204C}"

[HKEY_CLASSES_ROOT\CLSID\{45C5732A-9C24-11D3-9EEE-0090278B204C}\VersionIndependentProgID]
@="USDA.USDAObject"


So I have changed the ThreadingModel to be Apartment, and tried it all again
as you said, still it didn't make any difference.

I would't directly assume something is wrong with this USDA.dll, IMO there is
something wrong with the way you are importing the USDA typelib.

I used the VS2005 to import the USDA.dll COM object.
Also tried importing it with:
TlbImp.exe" "USDA.dll" /verbose /sysarray /out:usda.interop.dll
Make sure that:
- the USDA.dll is registered (regsvr32.exe) and check it's apartment requirements,
it should be "apartment" or "both".
- no older versions of both, the native component and the csharp assembly (or exe)
remain registered, before you try this in sequence.

Was Single, so I changed its registry value to Apartment.
1. tlbimp usda.tlb /out:usda.interop.dll
2. set a reference to usda.interop.dll when compiling the C# code, for instance using
csc /r:usda.interop.dll xxxxxxx.cs
form the command-line.

I have used the VS2005 rebuild feature.
3. run regasm /tlb /codebase xxxxxxx.dll

It's an exe so I did:
regasm.exe COMdotNET.exe /tlb /codebase COMdotNET.tlb
4. in VB6, reset the references to xxxxxx.tlb and usda.tlb and rebuild build the VB6 client
Run your client and inspect the xxxxx.tlb using oleview.

Checked it the oleview - still the struct is defined in the COMdotNET
although it's originally defined in the USDA.dll native COM.
 
W

Willy Denoyette [MVP]

Sharon said:
I did all that but still the same.

In the registry I found the USDA is registered as:

[HKEY_CLASSES_ROOT\CLSID\{45C5732A-9C24-11D3-9EEE-0090278B204C}]
@="USDAObject Class"

[HKEY_CLASSES_ROOT\CLSID\{45C5732A-9C24-11D3-9EEE-0090278B204C}\InprocServer32]
@="D:\\Sharon's\\Rubbish\\COM-.NET Struct\\COM Objects\\USDA.dll"
"ThreadingModel"="Single"

[HKEY_CLASSES_ROOT\CLSID\{45C5732A-9C24-11D3-9EEE-0090278B204C}\ProgID]
@="USDA.USDAObject.1"

[HKEY_CLASSES_ROOT\CLSID\{45C5732A-9C24-11D3-9EEE-0090278B204C}\Programmable]

[HKEY_CLASSES_ROOT\CLSID\{45C5732A-9C24-11D3-9EEE-0090278B204C}\TypeLib]
@="{45C5731B-9C24-11D3-9EEE-0090278B204C}"

[HKEY_CLASSES_ROOT\CLSID\{45C5732A-9C24-11D3-9EEE-0090278B204C}\VersionIndependentProgID]
@="USDA.USDAObject"


So I have changed the ThreadingModel to be Apartment, and tried it all
again
as you said, still it didn't make any difference.

I would't directly assume something is wrong with this USDA.dll, IMO
there is
something wrong with the way you are importing the USDA typelib.

I used the VS2005 to import the USDA.dll COM object.
Also tried importing it with:
TlbImp.exe" "USDA.dll" /verbose /sysarray /out:usda.interop.dll
Make sure that:
- the USDA.dll is registered (regsvr32.exe) and check it's apartment
requirements,
it should be "apartment" or "both".
- no older versions of both, the native component and the csharp assembly
(or exe)
remain registered, before you try this in sequence.

Was Single, so I changed its registry value to Apartment.

You are fooling COM into believing it's an apartment object, but you are
fooling yourself, you need to adapt the ATL project settings.
I have used the VS2005 rebuild feature.


It's an exe so I did:
regasm.exe COMdotNET.exe /tlb /codebase COMdotNET.tlb


Checked it the oleview - still the struct is defined in the COMdotNET
although it's originally defined in the USDA.dll native COM.


Sorry, but I can't help you further with this, as I said before, I can't use
the USDA.dll from the project you sent by mail. This dll depends on an older
atl and C runtime version, that means I can't register the DLL
(regsvr32.exe). Also, don't waste your time with the tlb stuff, your problem
is due to something else.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top