473,796 Members | 2,669 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(TheHos t)

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

I converted it to(C#)

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

in my c# code.
[DllImport("OLDD LL",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 1206

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

Similar topics

0
2183
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), System.Runtime.InteropServices.MarshalAs (System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=6)> Public CorpNum As Char()
3
2707
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 to get by. hdrFormat = '16s 32s 32s B 8s H 8s H 4s H H 20s 64s 64s 64s 32s 32s 64s L L B B B B B 64s 64s' Any ideas on what I am doing wrong?
4
2433
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 *' to 'struct adpcm_state *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
28
3069
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
0
2824
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? GCC seems to not understand "struct stat64" (missing in the header "sys/stat.h") Coding something like: struct stat64 statbf; returns a "storage size of 'statbf' isn't known" error.
3
4358
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
4567
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 containing text. So... a. How should I represent these field in the C# struct? b. How do I convert that representation into C# strings? Thanks for any help
1
3406
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 value it doesnot give me the correct value but prints some garbage value. Why is it so? Is there any way to correct it because i think i have to declare it again in main() for initializing other variables. thanks, prads #include <iostream>...
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9525
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10452
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10169
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6785
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2924
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.