473,503 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
+ 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?
Nov 16 '05 #1
0 1056

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

Similar topics

0
1180
by: news.microsoft.com | last post by:
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...
6
14906
by: ~toki | last post by:
I'm triyng to use this function int result = NativeMethods.midiOutGetDevCaps( -1, ref pSI, (uint)Marshal.SizeOf(pSI) ); Docs say that pSI is a struct (below) typedef struct { WORD wMid;...
4
3512
by: C Learner | last post by:
Hi, I have an application which is using a dll written in C++. When the program go to the function below, it would raise an NullReferenceException at the line of PtrToStructure. public bool...
5
2215
by: param | last post by:
Declaring struct as static is creating problem with newer version of CC compiler 5.7 in solaris. e.g. static struct new_str { int a; int b; };
8
2230
by: nurxb01 | last post by:
Hi I have a very basic doubt. The application i'm working on has some old code already in place. There are some struct data type decleared in a .h file and are being used for RPC communication....
7
2959
by: abhijeet | last post by:
Hi, I am having some problem for getting values in struct from the c dll. I have following definition Type MBRINFO szMember As String * 80 ' member name array usLevel As Integer...
13
6979
EARNEST
by: EARNEST | last post by:
#include <string.h> #include <ncurses.h> #include <time.h> #include <stdlib.h> typedef struct builder{ int locX; int locY; char charValue_H; char charValue_T;
0
7198
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
7072
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
7271
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,...
0
7319
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...
1
6979
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
5570
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
4998
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
4666
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...
0
373
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.