473,763 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string marshalling in p/invoke

I'm trying to P/Invoke a method in shell32.dll. here's the method signature.

LPITEMIDLIST SHBrowseForFold er( LPBROWSEINFO lpbi );

and this is the parameter structure

typedef struct _browseinfo {
HWND hwndOwner;
LPCITEMIDLIST pidlRoot;
LPTSTR pszDisplayName;
LPCTSTR lpszTitle;
UINT ulFlags;
BFFCALLBACK lpfn;
LPARAM lParam;
int iImage;
} BROWSEINFO, *PBROWSEINFO, *LPBROWSEINFO;

and this is how I declared the import and structure in C#

[DllImport( "shell32.dl l" )]
private static extern IntPtr SHBrowseForFold er(
[MarshalAs( UnmanagedType.L PStruct ), In, Out] BrowseInfo lpbi );

[StructLayout( LayoutKind.Sequ ential )]
public class BrowseInfo
{
public IntPtr hwndOwner;
public IntPtr pidlRoot;
[MarshalAs( UnmanagedType.L PStr )]
public string pszDisplayName;
[MarshalAs( UnmanagedType.L PStr )]
public string lpszTitle;
public uint ulFlags;
[MarshalAs( UnmanagedType.F unctionPtr )]
public BrowseCallbackP roc lpfn;
public uint lParam;
public int iImage;
}

this works, but my question is, in the original structure pszDisplayName and
lpszTitle are declared as LPTStr (LPCTStr). now when I marshalled them as
LPTStr, and ran on w2k machine, they are marshalled as Unicode strings (which
is correct behavior on the given platform) but the data is in fact
incorrectly marshalled. the method is expected to work with ANSI strings
somehow, when it should really be working with Unicode. anyone know why that
is?

Nov 16 '05 #1
0 1200

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

Similar topics

12
6655
by: Dave Bailey | last post by:
I need to store an encrypted connection string in the web.config file. I have found several examples on the Net but nothing specific as to how to accomplish task. Thanks in advance, Dave
8
37888
by: johnsto | last post by:
I'm really stuck - can someone help me! I've got a basic setup consisting of two things: 1. A C# web service 2. An unmanaged C++ DLL The WS is intended to call some functions in the DLL. The DLL has some legacy code which requires char* in its method parameters. I also have a new file in the DLL which is basically an intermediary -
3
1543
by: awk | last post by:
Hi All I have a com dll written in VB6 (it's a User Function Library for my crystal reports - this allows me to write custom functions for Crystal which can be applied in Crystal formulas - none of this is relevant to the problem though (((I think)))). Anyway, the VB dll has one method that takes a string as an argument and returns a string. It passes the string arg to a C# library which is where the problem lies. The string arg...
4
23823
by: Scott Lemen | last post by:
Hi, Some Win APIs expect a structure with a fixed length string. How is it defined in VB .Net 2003? When I try to use the FixedLengthString class I get an "Array bounds cannot appear in type specifiers" error. Thank you, Scott
2
2157
by: Peter Wone | last post by:
I've written a class which does some long running background processing and returns multiple results via events. The class has an Execute() method which creates a thread and runs an internal method _execute() on it. When events fire they are running on the worker thread. To use this class from a form with event handlers that manipulate the UI, you have to write this public void MyForm_DocumentReady(object Sender, DocumentReadyEventArgs...
10
2549
by: Bryce Calhoun | last post by:
Hello, First of all, this is a .NET 1.1 component I'm creating. SUMMARY ----------------------- This component that I'm creating is, for all intents and purposes, a document parser (I'm actually deserializing a SOAP document into an object and parsing out the fields, but that's fairly immaterial to this
1
1548
by: jsshah | last post by:
Hi I want to marshal following Win32 struct into .NEt class or struct as I want to call a native dll function from a Csharp code. The win32 struct ----------------------- typedef struct _FILE_OBJECT_ID_BUFFER {
3
8707
by: Morgan Cheng | last post by:
In P/Invoke situation, If some *out* parameter is LPWSTR, I can use string or StringBuilder. However, there is one problem about StringBuilder. By default, its Capacity is 16. If the returned string length is larger than 16. An ArgumentOutOfRangeExceptoin is raised. However, if string is used, no exception. I searched this topic. It is said that StringBuilder is preferred in this case, because the performance is better. I don't think so....
3
397
by: Saad | last post by:
Hi, I have a struct as follows: public __gc struct STTemp { public: int someint; System::Collections::ArrayList* arrTemp;
0
9563
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...
1
9938
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
9822
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
8822
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...
1
7366
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
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
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.