473,385 Members | 1,720 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.

Marshalling STRING from COM dll 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 20 '05 #1
3 1524
Cor
Hi AWK,

Did you know that you did post to the VB.net language news group.

The C# language newsgroup is one floor higher, above the JavaScript
newsgroup.

Cor

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[].

Nov 20 '05 #2
* "Cor" <no*@non.com> scripsit:
Did you know that you did post to the VB.net language news group.

The C# language newsgroup is one floor higher, above the JavaScript
newsgroup.


The solution will be similar for VB.NET and C#. But maybe the interop
newsgroup is the better place to post the question
(microsoft.public.dotnet.framework.interop).

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
> 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[].
I have stumbled across something similar while doing API work in VB 6.0:
String data is internally stored in Unicode format, but any time it passes
out of it's code block (calling an automation object or an API), string data
is converted to ANSI automatically by the runtime.

That's why it's *so hard* to call unicode API functions -- because even
though your VB6 string is unicode in memory, it is always passed as ANSI. I
bet you're having something similar happen here.

I like Herfried's answer -- go sniffing around the Runtime.Interop people
and namespace. The solution that I implemented is not really relevant (it
was strictly VB6 / API) and it was a huge heap of scary code that hacked
bits and stuff.

You mentioned using a Byte[]. If you do try something like this, remember
that ANSI characters are 1 byte each and Unicode characters could be 2, 3 or
even 4 bytes each, depending on the encoding.
--
Peace & happy computing,

Mike Labosh, MCSD MCT
Owner, vbSensei.Com
"Escriba coda ergo sum." -- vbSensei
"awk" <si*********@mbox.com.au> wrote in message
news:#K**************@TK2MSFTNGP09.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)))).

Any help greatly appreciated

S

Nov 20 '05 #4

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

Similar topics

2
by: Rookie | last post by:
Hi, I had a question on DllImport. On importing a function from a VC++ dll using DllImport (to a C# program), the function argument data types and the return types may be of a type that is not...
1
by: halise | last post by:
hello, i am trying to wrap an unmanaged C++ code to managed one so that i can use it within c#, and i am using IJW - "It Just Works" - method for that. In the code, there is a function which...
1
by: Reynardine | last post by:
I am calling a C/C++ DLL from C# and I am marshalling the parameters to the API call by doing a type conversion for each parameter. For example, here is my C++ API method : short int XENO_API...
2
by: Travis | last post by:
I'm working on a project where we're building a .NET wrapper to IBM's MQ Workflow C++ API. My original intention was to wrap the Workflow API with a managed C++ assembly that in turn could be...
2
by: BartMan | last post by:
Greetings, When working with managed c++, do you have to do anything special when going from simple types from managed to unmanaged and vice versa. Or is marshalling handled automatically for...
6
by: Ananas | last post by:
Hi, My native C++ function creates a dynamic array. I'm marshalling it to managed code and got to delete after. How to make it: c++ code: void CreateArrayInside( pTestStruct &TestStruct,...
1
by: Beorne | last post by:
I have a cpp application with this structure: //////////////C++/////////////// typedef struct StatusStructure { char FixedLenString; long LongVariable; double DoubleVariable; BOOL...
11
by: Daniel Bass | last post by:
Greetings! I'm trying to call this method in a c# app... SNAPIDLL_API int __stdcall SNAPI_SetCapabilitiesBuffer(HANDLE DeviceHandle, unsigned char *pData, long max_length); So far I've got...
2
by: calenlas | last post by:
Hi all, I'm taking my first steps into C# <--C++ DLL Interop and unfortunately I've run into (what seems to be) a very complicated case as my first task. Perhaps someone here can help me. I...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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.