473,387 Members | 1,455 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.

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 723

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

Similar topics

0
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
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
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
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
0
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
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
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
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
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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...

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.