473,406 Members | 2,769 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,406 software developers and data experts.

API structure & function conversion [ vb6 -> c# ]

hi everybody!

maybe there is somebody out there, who can give me a
little bit of help with this piece of vb6 code, I want
to 'translate' into c# - but I cannot handle it.
Type uddtData
aLongVariable1 as Long
aFixedLenghtNullTermString1 as String * 60
aFixedLenghtNullTermString2 as String * 34
aLongVariable2 as Long
End Type

Declare Function DoSomething Lib "Any.dll" (ByRef
hAnyHandle as Long, ByRef Data as uddtData, ByVal anyLong
as Long) as Long
I try to not despair too much of all the structure
attributes, marshalling attributes and
System.Runtime.InteropServices - but I'm about to give up.
any pretty good ideas?
many thanx in advance! and a happy new year, of course!

bye - h.
Nov 15 '05 #1
2 1136
Harry,

The declaration you want is as follows:

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct uddtData
{
public int aLongVariable1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=60)]
public string aFixedLengthNullTermString1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=34)]
public string aFixedLengthNullTermString2;
public int aLongVariable2;
}

The key is in specifying the fixed width strings.

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

"harry" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
hi everybody!

maybe there is somebody out there, who can give me a
little bit of help with this piece of vb6 code, I want
to 'translate' into c# - but I cannot handle it.
Type uddtData
aLongVariable1 as Long
aFixedLenghtNullTermString1 as String * 60
aFixedLenghtNullTermString2 as String * 34
aLongVariable2 as Long
End Type

Declare Function DoSomething Lib "Any.dll" (ByRef
hAnyHandle as Long, ByRef Data as uddtData, ByVal anyLong
as Long) as Long
I try to not despair too much of all the structure
attributes, marshalling attributes and
System.Runtime.InteropServices - but I'm about to give up.
any pretty good ideas?
many thanx in advance! and a happy new year, of course!

bye - h.

Nov 15 '05 #2
Hi Nicholas
Thank you for the answer
Best wishes! Bye - Harry
Nov 15 '05 #3

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

Similar topics

4
by: josef angermeier | last post by:
i wrote a display driver for a lcd segment display which doesnt recognize ascii character so that each character of an output string needs to be converted byte by byte by looking in a const...
11
by: Mannequin* | last post by:
Hi all, I'm working on a quick program to bring the Bible into memory from a text file. Anyway, I have three questions to ask. First, is my implementation of malloc () correct in the program to...
10
by: lovecreatesbeauty | last post by:
Is parameter type conversion required for the 2nd argument on printf("%p", (void *)&i); ? But one would never call memcpy like: memcpy((void *)pi, (void *)pj, sizeof *pj); /*memcpy((void *)pi,...
11
by: aaragon | last post by:
Hi everyone. I'm trying to write a class with policy based design (Alexandrescu's Modern C++ Design). I'm not a programmer but an engineer so this is kind of hard for me. Through the use of...
16
by: pkoniusz | last post by:
Hello everybody, Been just thinking how actually one could convert the following unmanaged code to the managed C++: struct JustAnExample { char value1; int value2; // etc ....
42
by: coder_lol | last post by:
Thanks everyone again for contributing to helping me clear C++ confusions. I did some serious reading on copy constructors and assignments and I think I've got a good handle on the memory stuff. ...
3
by: Szabolcs | last post by:
Consider the attached example. When I try to compile it (with g++ 4.1.2), I get the error message error: no matching function for call to 'fun(A<int>&)' However, if I do not use templates, it...
3
by: Daniel Kraft | last post by:
Hi, I was curious whether or not to use the & operator when creating a function pointer. It seems, that both &func and plain func create a pointer of the appropriate function pointer type. ...
14
by: deepak | last post by:
Hi Experts, I'm getting this compilation error while trying to access a member in structure. at what time we will get this error message? Thanks, Deepak
10
by: Scott Townsend | last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent it to be in specific places (not yet 100% defined). I wanted to create a structure/class with all of the data in it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
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...

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.