473,486 Members | 2,353 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

struct covnertion(VB->C#) problem

hello, all.
I am trying to convert a struct from VB to c# in order to use an old DLL.
Here is the definition in VB

Public Type CHost
Host As String * 60
Port As String * 5
Info As String * 120 'Inof returned from host
Timeout As String * 10
End Type

In the sample VB code:
Public Declare Function CConnect Lib "OLDDLL.DLL" (Host As CHost) As Integer
iError = CConnect(TheHost)

and then the CHost.Info was set by the remote host.

I converted it to(C#)

public struct CHost
{
[System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.Unm
anagedType.ByValTStr,SizeConst=60)]
public string Host; //host name
[System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.Unm
anagedType.ByValTStr,SizeConst=5)]
public string Port; //host port
[System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.Unm
anagedType.ByValTStr,SizeConst=120)]
public string Info; //Info returned from remote host
[System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.Unm
anagedType.ByValTStr,SizeConst=5)]
public string Timeout; //timeout
};

in my c# code.
[DllImport("OLDDLL",EntryPoint="CConnect")]
public static extern short CConnect(ref CHost Host);

short ierror = CConnect(ref theHost);

I can connect to the remote host but the theHost.Info was not set.

Could anybody let me know what I was doing wrong and what is the right way
to do it?
Jul 21 '05 #1
0 1173

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

Similar topics

0
2162
by: Yuri | last post by:
Hello everyone. I'm trying to use CopyMemory API in VB.NET. I have a module with struct defined like this: <StructLayout(LayoutKind.Sequential)> _ Public Structure tSortKey <VBFixedString(6),...
3
2688
by: Chandu | last post by:
In using the following struct format I get the size as 593. The same C struct is 590 if packed on byte boundary and 596 when using pragma pack(4). I am using pack(4) and added 3 spares at the end...
4
2401
by: quek | last post by:
Im having a problem passing a struct ptr. Maybe someone could help me. Heres what Visual C gives me as error: error C2664: 'adpcm_coder_u' : cannot convert parameter 4 from 'struct main::$S1 *'...
28
2997
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
0
2800
by: ccfq | last post by:
I have a problem with GCC and C. (under Windows XP, CPU 32-bit Athlon XP, gcc version 3.4.5, mingw special) Is there some simple way to return the size of a large file (2GB+) without opening it?...
3
4325
by: angshuman.agarwal | last post by:
Structure in C DLL ---------------------------- typedef struct IrData { unsigned short uiFormat; unsigned short uiLength; unsigned char* pchData; } tagIrData; Function in C DLL
1
4562
by: PLS | last post by:
I'm trying to write the definition of a struct that must exactly match the binary layout of a struct created by a native c++ program. The C++ struct contains several wchar_t and char fields...
1
3389
by: prads | last post by:
hello, i have a struct and have declared it as shown below. If i print its value in the main() fn it prints it correctly.However if i declare the struct again in the main() and try to print its...
0
6967
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
7132
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,...
1
6846
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
7341
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
5439
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,...
1
4870
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...
0
4564
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...
1
600
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.