473,573 Members | 4,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

win32 DLL and LPTSTR

Hi there.

Having a problem calling a win32 function from a dll.
Here is the function header:

DWORD thrdGetHcNum (DWORD nPort, DWORD nBaudrate, LPTSTR lpszHcNum)

//Description of the 3rd parameter
LpszHcNum: The head of the buffer area used to store the serial number
of the terminal, 9 bytes at least.

Here is my code:

[DllImport("comd ll.dll", SetLastError = true)]
public static extern uint thrdGetHcNum(in t nPort, int nBaudrate,
[MarshalAs(Unman agedType.LPTStr )] ref StringBuilder lpszHcNum);

//The actual call
StringBuilder Buffer = new StringBuilder(1 0);
result=thrdGetH cNum(Port,Baud, ref Buffer);

Everytime I runt his, I get a Object not set to reference error.
Can anyone tell me what I am doing wrong?
I have tried using a string, a char[] buf = new[10], MarshalAs.LPTst r
and MarshalAs.Array but always hit the same problem.

I am calling other functions from the dll without any problem. The only
difference with this one is I should be getting a string back with some
data in it.

Any help on this would be appreciated.

Regards,

Steven


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
1 5973
> [DllImport("comd ll.dll", SetLastError = true)]
public static extern uint thrdGetHcNum(in t nPort, int nBaudrate,
[MarshalAs(Unman agedType.LPTStr )] ref StringBuilder lpszHcNum);


I think that "ref" is not necessary here. Reference types are always passed
by reference. With "ref" you pass a reference to the reference.

[DllImport("comd ll.dll", SetLastError = true)]
public static extern uint thrdGetHcNum(in t nPort, int nBaudrate,
[MarshalAs(Unman agedType.LPTStr )] StringBuilder lpszHcNum);

I hope this will help
Regards, Wiktor Zychla
Nov 16 '05 #2

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

Similar topics

4
10176
by: sorty | last post by:
Hi, I have read in many places that TCHAR can be 'char' or 'wchar_t' depending on ANSI or UNICODE. I have also read that LPTSTR is a long pointer to a TCHAR. I am confused about the following. Please answer with yes/no and then elaborate as you please..
9
25775
by: alex | last post by:
how do i initialize an LPTSTR variable? i'm trying to call a microsoft function LONG QueryStringValue( LPCTSTR pszValueName, LPTSTR pszValue, ULONG* pnChars ) throw( );pszValue is supposed to get the value i want but i need to initialize it before i pass it to QueryStringValue, how do i initialize
7
29322
by: Vincent Nguyen | last post by:
Hi, Does anyone know how call Win32 native API GetTokenInformation() by using C#? Any sample code would be helpful. Thanks! Vincent
6
2126
by: Rajesh | last post by:
I am a System Administrator and do some programming (Admin Utlities) in VB6 & C#.net. I am interested in Win32 and thought of learning C++ (as it is a pre-requsite) and read 13 chapters from C++.Net Complete Reference. I think I can now follow a normal C++ program but when it comes to Win32 most books I have seen does not explain anything on the...
3
2594
by: Steve Long | last post by:
Hello, I have developed a small win32 dll in C++ and exported a function from it using a DEF file. I'm using the DllImport attribute to import this function. I've tested the function in a vsc++ console app, (just the code not as a dll), and it works as expected. However, I'm having some trouble using it from my C# app. Is there a way I can...
1
2609
by: Lewap | last post by:
Hi! I've piece of code like follow: <code> LPTSTR lpszPipename = (LPTSTR) "\\\\.\\pipe\\testpipe"; hPipe = CreateNamedPipe(
8
5748
by: **Developer** | last post by:
Been reading some of the Marshal doc and am a little confused. Anyway, I've been using the following and it works OK. Public Declare Auto Function SHGetFolderPath Lib "shell32.dll" (ByVal hWnd As Integer, _ ByVal nFolder As Integer, ByVal nToken As Integer, _ ByVal dwFlags As Integer, _
1
5628
by: chriskent | last post by:
Hi, I have an unusual situation whereby we create a Window during initialisation. We have used this code for many years and have found one unusual case with a customer when the RegiterClass fails and then the following CreateWindow also fails, making our process timeout and fail. My real problem is trying to understand what is causing the...
4
1834
by: flingor | last post by:
Hello everyone! When I start a "Win32 Project" with Microsoft's Visual C++ I can't produce any output by using my "normal" C++ code that I would use in a console application. First, I'm not sure if i place my code in the right position, but I think I'm right as I don't get any error messages and the comments by Visual C++ tell me the right...
0
7789
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...
0
8037
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. ...
0
8215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7800
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...
0
8086
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...
0
6432
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...
1
5605
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3737
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2227
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.