473,385 Members | 1,610 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,385 software developers and data experts.

Problems with Interop in C#

Subject: Problems with Interop in C#

We are having problems using Interop with a Vb6 ActiveX Dll in C# code in
Net2 using Vs2005. Below are the signatures of the method that is the
problem. It is the last argument (e.g., "out obj" in C#) that is returned
corrupted. It should be an array of integers. In one simple test App this
argument does return an array of integers reliably. In the actual App it
returns one or two integer arrays but then it starts returning corrupted
data. The difference between the two App's is on of complexity and that the
actual App uses many more threads then the test App.

We use Tlbimp.exe in the PreBuild step. We do not have the Vb6 code or Pdb
file.

ANY suggestions would be GREATLY appreciated.

C# signature--
bool b=pdc.Get_ArrayData(out Transfer_Complete,out DataNum,out
SamplingPeriod,out obj);

IDL signature--
[id(0x00000012), helpstring("method Get_ArrayData")]
VARIANT_BOOL Get_ArrayData(
[out] long* Transfer_Complete,
[out] long* DataNum,
[out] double* SamplingPeriod,
[out] VARIANT* arrayData);

--
John Olbert

Nov 1 '06 #1
8 2666

"John Olbert" <so*****@snet.netwrote in message
news:69**********************************@microsof t.com...
| Subject: Problems with Interop in C#
|
| We are having problems using Interop with a Vb6 ActiveX Dll in C# code in
| Net2 using Vs2005. Below are the signatures of the method that is the
| problem. It is the last argument (e.g., "out obj" in C#) that is returned
| corrupted. It should be an array of integers. In one simple test App this
| argument does return an array of integers reliably. In the actual App it
| returns one or two integer arrays but then it starts returning corrupted
| data. The difference between the two App's is on of complexity and that
the
| actual App uses many more threads then the test App.
|
| We use Tlbimp.exe in the PreBuild step. We do not have the Vb6 code or Pdb
| file.
|
| ANY suggestions would be GREATLY appreciated.
|
| C# signature--
| bool b=pdc.Get_ArrayData(out Transfer_Complete,out DataNum,out
| SamplingPeriod,out obj);
|
| IDL signature--
| [id(0x00000012), helpstring("method Get_ArrayData")]
| VARIANT_BOOL Get_ArrayData(
| [out] long* Transfer_Complete,
| [out] long* DataNum,
| [out] double* SamplingPeriod,
| [out] VARIANT* arrayData);
|
| --
| John Olbert
|

Make sure your threads are initialized for STA.

Willy.
Nov 1 '06 #2
as far as im aware you cannot use arrays by reference across the interop
boundary

--
"If ignorance is bliss, then wipe the smile from my face."
"Willy Denoyette [MVP]" wrote:
>
"John Olbert" <so*****@snet.netwrote in message
news:69**********************************@microsof t.com...
| Subject: Problems with Interop in C#
|
| We are having problems using Interop with a Vb6 ActiveX Dll in C# code in
| Net2 using Vs2005. Below are the signatures of the method that is the
| problem. It is the last argument (e.g., "out obj" in C#) that is returned
| corrupted. It should be an array of integers. In one simple test App this
| argument does return an array of integers reliably. In the actual App it
| returns one or two integer arrays but then it starts returning corrupted
| data. The difference between the two App's is on of complexity and that
the
| actual App uses many more threads then the test App.
|
| We use Tlbimp.exe in the PreBuild step. We do not have the Vb6 code or Pdb
| file.
|
| ANY suggestions would be GREATLY appreciated.
|
| C# signature--
| bool b=pdc.Get_ArrayData(out Transfer_Complete,out DataNum,out
| SamplingPeriod,out obj);
|
| IDL signature--
| [id(0x00000012), helpstring("method Get_ArrayData")]
| VARIANT_BOOL Get_ArrayData(
| [out] long* Transfer_Complete,
| [out] long* DataNum,
| [out] double* SamplingPeriod,
| [out] VARIANT* arrayData);
|
| --
| John Olbert
|

Make sure your threads are initialized for STA.

Willy.
Nov 1 '06 #3

"fallenidol" <fa********@discussions.microsoft.comwrote in message
news:D6**********************************@microsof t.com...
| as far as im aware you cannot use arrays by reference across the interop
| boundary
|
| --
| "If ignorance is bliss, then wipe the smile from my face."
|
Sure you can, the OP's case is a bit tricky as he is passing a VARIANT*, so
what you need is to pass an object reference (effectively a VARIANT*).

Consider following sample...

' SomeAXClass in VB6

Function GetArray(o As Variant) As Boolean
' no bound checks in this sample!!!!!
o(0) = 100
o(1) = 200
End Function

// C#...
....
SomeAXClass o = new SomeAXClass();
object arr = new object[2];
o.GetArray(ref arr);
foreach(object i in arr as object[])
Console.WriteLine(i.ToString());
...

The only problem I have with the OP's code is that I don't believe this is a
VB6 AX dll, see my reply to his posting for details on why.
Willy.
Nov 1 '06 #4

"John Olbert" <so*****@snet.netwrote in message
news:69**********************************@microsof t.com...
| Subject: Problems with Interop in C#
|
| We are having problems using Interop with a Vb6 ActiveX Dll in C# code in
| Net2 using Vs2005. Below are the signatures of the method that is the
| problem. It is the last argument (e.g., "out obj" in C#) that is returned
| corrupted. It should be an array of integers. In one simple test App this
| argument does return an array of integers reliably. In the actual App it
| returns one or two integer arrays but then it starts returning corrupted
| data. The difference between the two App's is on of complexity and that
the
| actual App uses many more threads then the test App.
|
| We use Tlbimp.exe in the PreBuild step. We do not have the Vb6 code or Pdb
| file.
|
| ANY suggestions would be GREATLY appreciated.
|
| C# signature--
| bool b=pdc.Get_ArrayData(out Transfer_Complete,out DataNum,out
| SamplingPeriod,out obj);
|
| IDL signature--
| [id(0x00000012), helpstring("method Get_ArrayData")]
| VARIANT_BOOL Get_ArrayData(
| [out] long* Transfer_Complete,
| [out] long* DataNum,
| [out] double* SamplingPeriod,
| [out] VARIANT* arrayData);
|
| --
| John Olbert
|

Are you sure this (the above IDL) is from a VB6 AXCOM dll?, AFAIK VB6 can't
pass an argumant as out, it passes arguments as [In, Out] or [In]. Returns
are passed as [out, retval] and the IDL signature doesn't seem right for
VB6, it should return an HRESULT
If i was a VB6 AX object it's methods signature should look something like
this:

HRESULT GET_....([In, Out] long* ...., [in, out] VARIANT*, [in, retval]
VARIANT_BOOL*);
Willy.

Nov 1 '06 #5
All we have is the raw Dll. Is there a way to find out which compiler was used?

Thanks for the idea.
--
John Olbert

"Willy Denoyette [MVP]" wrote:
>
"John Olbert" <so*****@snet.netwrote in message
news:69**********************************@microsof t.com...
| Subject: Problems with Interop in C#
|
| We are having problems using Interop with a Vb6 ActiveX Dll in C# code in
| Net2 using Vs2005. Below are the signatures of the method that is the
| problem. It is the last argument (e.g., "out obj" in C#) that is returned
| corrupted. It should be an array of integers. In one simple test App this
| argument does return an array of integers reliably. In the actual App it
| returns one or two integer arrays but then it starts returning corrupted
| data. The difference between the two App's is on of complexity and that
the
| actual App uses many more threads then the test App.
|
| We use Tlbimp.exe in the PreBuild step. We do not have the Vb6 code or Pdb
| file.
|
| ANY suggestions would be GREATLY appreciated.
|
| C# signature--
| bool b=pdc.Get_ArrayData(out Transfer_Complete,out DataNum,out
| SamplingPeriod,out obj);
|
| IDL signature--
| [id(0x00000012), helpstring("method Get_ArrayData")]
| VARIANT_BOOL Get_ArrayData(
| [out] long* Transfer_Complete,
| [out] long* DataNum,
| [out] double* SamplingPeriod,
| [out] VARIANT* arrayData);
|
| --
| John Olbert
|

Are you sure this (the above IDL) is from a VB6 AXCOM dll?, AFAIK VB6 can't
pass an argumant as out, it passes arguments as [In, Out] or [In]. Returns
are passed as [out, retval] and the IDL signature doesn't seem right for
VB6, it should return an HRESULT
If i was a VB6 AX object it's methods signature should look something like
this:

HRESULT GET_....([In, Out] long* ...., [in, out] VARIANT*, [in, retval]
VARIANT_BOOL*);
Willy.

Nov 1 '06 #6

"John Olbert" <so*****@snet.netwrote in message
news:AD**********************************@microsof t.com...
| All we have is the raw Dll. Is there a way to find out which compiler was
used?
|

Not really, all you can do to make sure it's a VB6 dll is run dumpbin.exe
and check the imports, a VB6 PE must import the VB runtime (MSVBVM60.dll).
PE files produced by other tools will not import the VB runtime, but you
won't be able to tell what language compiler was used to build the file.

Willy.
Nov 2 '06 #7
Off hand how do you make sure that one's .NET2 threads initialized for STA?

Thanks.
--
John Olbert

"Willy Denoyette [MVP]" wrote:
>
"John Olbert" <so*****@snet.netwrote in message
news:69**********************************@microsof t.com...
| Subject: Problems with Interop in C#
|
| We are having problems using Interop with a Vb6 ActiveX Dll in C# code in
| Net2 using Vs2005. Below are the signatures of the method that is the
| problem. It is the last argument (e.g., "out obj" in C#) that is returned
| corrupted. It should be an array of integers. In one simple test App this
| argument does return an array of integers reliably. In the actual App it
| returns one or two integer arrays but then it starts returning corrupted
| data. The difference between the two App's is on of complexity and that
the
| actual App uses many more threads then the test App.
|
| We use Tlbimp.exe in the PreBuild step. We do not have the Vb6 code or Pdb
| file.
|
| ANY suggestions would be GREATLY appreciated.
|
| C# signature--
| bool b=pdc.Get_ArrayData(out Transfer_Complete,out DataNum,out
| SamplingPeriod,out obj);
|
| IDL signature--
| [id(0x00000012), helpstring("method Get_ArrayData")]
| VARIANT_BOOL Get_ArrayData(
| [out] long* Transfer_Complete,
| [out] long* DataNum,
| [out] double* SamplingPeriod,
| [out] VARIANT* arrayData);
|
| --
| John Olbert
|

Make sure your threads are initialized for STA.

Willy.
Nov 2 '06 #8

"John Olbert" <so*****@snet.netwrote in message
news:DE**********************************@microsof t.com...
| Off hand how do you make sure that one's .NET2 threads initialized for
STA?
|
| Thanks.
| --
| John Olbert
|
|

When it's your main thread, you can apply the [STAThread] attribute to your
Main function.
When it's an auxiliary thread, initialize the thread instance as STA, using
the SetApartentState method before it is started.

Worker threads picked from the thread pool are MTA and cannot be changed.

Willy.

Nov 2 '06 #9

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

Similar topics

0
by: keefah | last post by:
Hi, I'm writing a C# web app that uses Outlook to send email. I use a reference to the Microsoft Outlook 11.0 Object Library, but it's giving me problems. I tracked down some stuff on the Net...
1
by: em | last post by:
Hi all, I'm getting some problems importing a DLL that I made in C# within VB6.0. The C# is quite easy, just for trying: namespace TestDll { public class Class1
1
by: Shiro | last post by:
Hi I have read the various postings relating to Interop strong name signing and cannot find an example similar to mine. I have stringly named my AxInterops/Interops and they all work just...
5
by: Dave | last post by:
I have an existing VC6 ATL COM DLL. It has a number of methods within it that take a byte array as the methods parameters. Here's what the IDL looks like in the VC6 DLL: HRESULT...
0
by: Tobester | last post by:
Hi I am having problems accessing a vb6 dll from ASP.Net. The vb6 dll is registered. I have then created an interop file using tlbimp. The interop has been added to the GAC. I can run the...
0
by: John Olbert | last post by:
Subject: Problems with Interop in C# We are having problems using Interop with a Vb6 ActiveX Dll in C# code in Net2 using Vs2005. Below are the signatures of the method that is the problem. It...
5
by: =?Utf-8?B?U3R1YXJ0?= | last post by:
Hi There I have been having a play around with the following code to display a datagrid in Excel (all from Steve Orr's site): Private Sub btnTechServAccred_Click(ByVal sender As System.Object,...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
0
by: Jason Hamilton | last post by:
Hey all, I have written a Windows Forms application in VB.NET that creates a WCF Server. This server uses the Microsoft.Office.Interop.Access library to get a list of all of the MS Access...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.