473,804 Members | 3,094 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2046
awk,

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

[return:MarshalA s(UnmanagedType .BStr)]
public string MyMethod([MarshalAs(Unman agedType.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.co m

"awk" <si*********@mb ox.com.au> wrote in message
news:Oi******** ******@tk2msftn gp13.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(dat a As String) As String

Dim reco
Set reco =
CreateObject("I conGlobal.Carel inkPlus.Reports Utilities.Cryst alReportsUtilit y
")
Reconstruct = reco.Reconstruc tData(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.c om> wrote in
message news:u$******** ******@TK2MSFTN GP10.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:MarshalA s(UnmanagedType .BStr)]
public string MyMethod([MarshalAs(Unman agedType.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.co m

"awk" <si*********@mb ox.com.au> wrote in message
news:Oi******** ******@tk2msftn gp13.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
3477
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 managed object to reference the same region of memory. Question 1: should I call Marshal.FreeCoTaskMem after calling Marshal.PtrToStructure? Question 2: the Marshal.PtrToStructure method seems to create an object for the structure -- should...
2
11640
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 that needs to be returned to the caller (C#) { short snOperParams; TCHAR szNFPath; TCHAR szSSFile; TCHAR szExeFile;
1
4221
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 I call to GetTokenInformation I receive a buffer size (see //HERE... comment in code), but when I let the code continue, asp.net just sits there returning nothing, apparently on the Marshal.AllocHGlobal call. Here's the library function:
0
2694
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 mixed mode DLL unmanaged code is written in unmanaged C++ & resides in an unmanaged DL Product used is VS.NET 200 Please tell me what is the best practice for getting and setting data fro unmanaged to managed part when I have a class with...
13
2172
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 code? Thanks PS I added the +1 because as I understand the GetLogicalDriveStrings doc
21
2586
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) >>> type(bytes) <type 'str'>
2
3188
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
6318
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: public static extern int AddData(IntPtr data);
5
1995
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 str(123) == str("123") or are they different?
0
9569
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9130
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.