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

Marshal strings from COM to Managed Code?

awk
Hi All

I have a com dll written in VB6 (it's a User Function Library for my crystal
reports - this allows me to write custom functions for Crystal
which can be applied in Crystal formulas - none of this is relevant to the
problem though (((I think)))).
Anyway, the VB dll has one method that takes a string as an argument and
returns a string. It passes the string arg to a C# library
which is where the problem lies. The string arg contains unicode data and
when it passes it to the c# managed code the unicode is lost
and turns into ???????????????? characters which means the c# code doesnt
know what to do with it (it needs the unicode string). Therefore I think
that the marshalling process of the string from vb dll to c# dll is my
issue. What do I have to do to marshall this string properly? Should I be
marshalling it as a string or perhaps a byte[].

Any help greatly appreciated

S
Nov 15 '05 #1
2 2023
awk,

I assume you are using COM interop to access the C# method in VB6. Your
method needs to be attributed like this:

[return:MarshalAs(UnmanagedType.BStr)]
public string MyMethod([MarshalAs(UnmanagedType.BStr)] string param1);

While I think that it does this by default (if you are using com
interop), this should explicitly set it.

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

"awk" <si*********@mbox.com.au> wrote in message
news:Oi**************@tk2msftngp13.phx.gbl...
Hi All

I have a com dll written in VB6 (it's a User Function Library for my crystal reports - this allows me to write custom functions for Crystal
which can be applied in Crystal formulas - none of this is relevant to the
problem though (((I think)))).
Anyway, the VB dll has one method that takes a string as an argument and
returns a string. It passes the string arg to a C# library
which is where the problem lies. The string arg contains unicode data and
when it passes it to the c# managed code the unicode is lost
and turns into ???????????????? characters which means the c# code doesnt
know what to do with it (it needs the unicode string). Therefore I think
that the marshalling process of the string from vb dll to c# dll is my
issue. What do I have to do to marshall this string properly? Should I be
marshalling it as a string or perhaps a byte[].

Any help greatly appreciated

S

Nov 15 '05 #2
awk
Thanks Nicholas

I gave it a try but still I get ????????????????????? as the value of the
methods parameter.
Here is the VB6 Method that makes the call :

Public Function Reconstruct(data As String) As String

Dim reco
Set reco =
CreateObject("IconGlobal.CarelinkPlus.ReportsUtili ties.CrystalReportsUtility
")
Reconstruct = reco.ReconstructData(data)

End Function

Is that all I need to do to make a call to the managed code (it was in the
example I have - using late binding).
Also I should mention that the string being passed to the VB method is being
passed from
a Crystal Reports formula (the vb method is part of a Crystal UFL).

Thanks

S
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:u$**************@TK2MSFTNGP10.phx.gbl...
awk,

I assume you are using COM interop to access the C# method in VB6. Your method needs to be attributed like this:

[return:MarshalAs(UnmanagedType.BStr)]
public string MyMethod([MarshalAs(UnmanagedType.BStr)] string param1);

While I think that it does this by default (if you are using com
interop), this should explicitly set it.

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

"awk" <si*********@mbox.com.au> wrote in message
news:Oi**************@tk2msftngp13.phx.gbl...
Hi All

I have a com dll written in VB6 (it's a User Function Library for my

crystal
reports - this allows me to write custom functions for Crystal
which can be applied in Crystal formulas - none of this is relevant to the problem though (((I think)))).
Anyway, the VB dll has one method that takes a string as an argument and
returns a string. It passes the string arg to a C# library
which is where the problem lies. The string arg contains unicode data and when it passes it to the c# managed code the unicode is lost
and turns into ???????????????? characters which means the c# code doesnt know what to do with it (it needs the unicode string). Therefore I think
that the marshalling process of the string from vb dll to c# dll is my
issue. What do I have to do to marshall this string properly? Should I be marshalling it as a string or perhaps a byte[].

Any help greatly appreciated

S


Nov 15 '05 #3

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

Similar topics

1
by: Ken Allen | last post by:
The documentation is not clear on the exact behaviour of the Marshal.PtrToStructure method and whether it copies the contents of the IntPtr region to a new managed object or whether it creates the...
2
by: zDog | last post by:
I found a lot of information on passing data from C# to a C++ dll What I cannot find is a way to return C++ structs of TCHAR string data back to the C# managed code! typedef struct // C++ data...
1
by: dhornyak | last post by:
I have been banging my head against the wall for a while now, and can't seem to id the problem. I've been through a ton of posts and the code doesn't seem any different. Can anybody see it? When...
0
by: Johannes Unfried | last post by:
Problem Best practice needed to marshal STL data from managed code to unmanaged code & vice vers Details managed code is written in managed C++ & accesses the unmanaged code (i.e. lives in a...
13
by: Just Me | last post by:
The following almost works. The problem is Marshal.PtrToStringAuto seems to terminate at the first null so I don't get the full string. Any suggestions on how to fix this? Or how to improve the...
21
by: Mike | last post by:
Hi, The example below shows that result of a marshaled data structure is nothing but a string >>> data = {2:'two', 3:'three'} >>> import marshal >>> bytes = marshal.dumps(data) >>>...
2
by: RYoung | last post by:
Given this native struct: typedef struct vendor { char name; } VENDOR I want to make managed equivalent, so I did this: public value struct Vendor
1
by: nicewenyan | last post by:
I want to pass a managed c# byte (8 bit) array into a unmanaged c++ function: extern "C" void AddData(unsigned int* data); I use P/Invoke on managed side to do the marshaling as following: ...
5
by: Anurag | last post by:
I have been chasing a problem in my code since hours and it bolis down to this import marshal marshal.dumps(str(123)) != marshal.dumps(str("123")) Can someone please tell me why? when...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
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
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...

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.