473,382 Members | 1,639 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,382 software developers and data experts.

Need help converting structure to VB.Net

Hi there,

I've implemented a local system hook to suppress certain windows beeing
displayed by the axWebbrowser control. Now I need some more information
before I can decide, whether to suppress a window or not.

My callback function get a long pointer (lParam) to a structure which
contains further information. This structure is described at MSN as follows:

typedef struct tagCREATESTRUCT {
LPVOID lpCreateParams;
HINSTANCE hInstance;
HMENU hMenu;
HWND hwndParent;
int cy;
int cx;
int y;
int x;
LONG style;
LPCTSTR lpszName;
LPCTSTR lpszClass;
DWORD dwExStyle;
} CREATESTRUCT, *LPCREATESTRUCT;

I am trying to reference the structure by using the
Marshal.PtrToStructure(lParam, t.GetType()) method, where t is a local
var to the structure. But I don't seem to manage a correct
implementation of the above structure.

I'd really appreciate any help on this.

regards.
Nov 21 '05 #1
9 5641

Have you searched http://www.pinvoke.net ?

Basicly the handle and pointer members become IntPtrs, the ints, LONGs
and DWORDs translate to Integers and the LPCTSTRs become Strings.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2
Hi,

thanks for your reply. But translating LPCTSTR to Strings throws an
exception. I tried translating the rest like you said and keeping LPCSTR
as intPTR, but i am still getting strange values within my structure.

I'll check the given URL for more informations. Maybe I can find
something helpful.

Mattias Sjögren wrote:
Have you searched http://www.pinvoke.net ?

Basicly the handle and pointer members become IntPtrs, the ints, LONGs
and DWORDs translate to Integers and the LPCTSTRs become Strings.

Mattias

Nov 21 '05 #3
LPCStr's are actually unicode null terminating strings. If you look in the
..Net Framework/Platform SDK's they mention changing them to StringBuilder
rather than strings.

If you want me to convert it (structure) for you, I can, but really its not
very difficult

"Hugo Amselschlag" wrote:
Hi,

thanks for your reply. But translating LPCTSTR to Strings throws an
exception. I tried translating the rest like you said and keeping LPCSTR
as intPTR, but i am still getting strange values within my structure.

I'll check the given URL for more informations. Maybe I can find
something helpful.

Mattias Sjögren wrote:
Have you searched http://www.pinvoke.net ?

Basicly the handle and pointer members become IntPtrs, the ints, LONGs
and DWORDs translate to Integers and the LPCTSTRs become Strings.

Mattias

Nov 21 '05 #4
Crouchie,

"Crouchie1998" <Cr**********@discussions.microsoft.com> schrieb:
LPCStr's are actually unicode null terminating strings.


I have to disagree...

'LPCSTR' strings are pointers to constant, null-terminated strings of 8-bit
Windows (ANSI) characters.

'LPCTSTR' strings are 'LPSTR' strings on non-Unicode systems, and 'LPCWSTR'
strings on Unicode systems. 'LPCWSTR' strings are pointers to a constant
null-terminated string of 16-bit Unicode characters.

More information:

Platform SDK: Windows API -- Windows Data Types
<URL:http://msdn.microsoft.com/library/en-us/winprog/winprog/windows_data_types.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5
Addendum:

'StringBuilder' cannot be used in structures (MSDN: "Strings are valid
members of structures; however, 'StringBuilder' buffers are invalid in
structures."). Instead, use a string + 'MarshalAsAttribute' + corresponding
'UnmanagedType'. In our particular case, '<MarshalAs(UnmanagedType.LPTStr)>
lpszName As String', for example.

More information:

..NET Framework Developer's Guide -- Default Marshaling for Strings
<URL:http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondefaultmarshalingforstrings.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
In article <#i**************@tk2msftngp13.phx.gbl>, Hugo Amselschlag wrote:
Hi there,

I've implemented a local system hook to suppress certain windows beeing
displayed by the axWebbrowser control. Now I need some more information
before I can decide, whether to suppress a window or not.

My callback function get a long pointer (lParam) to a structure which
contains further information. This structure is described at MSN as follows:

typedef struct tagCREATESTRUCT {
LPVOID lpCreateParams;
HINSTANCE hInstance;
HMENU hMenu;
HWND hwndParent;
int cy;
int cx;
int y;
int x;
LONG style;
LPCTSTR lpszName;
LPCTSTR lpszClass;
DWORD dwExStyle;
} CREATESTRUCT, *LPCREATESTRUCT;


Structure CREATESTRUCT
Public lpCreateParams as IntPtr
Public hInstance As IntPtr
Public hMenu As IntPtr
Public hwndParent As IntPtr
Public cy As Integer
Public cx As Integer
Public y As Integer
Public x As Integer
Public style As Integer
Public lpszName As IntPtr
Public lpszClass As IntPtr
Public dwExStyle As Integer
End Structure

I assume your getting a IntPtr that referes to one of these
structures... You should be able to do something like:

Dim cs As CREATESTRUCT = _
CType (Marshal.PtrToStructure (theIntPtr, GetType (CREATESTRUCT)), _
CREATESTRUCT)

If you need to access the lpszName or lpszClass members, you'll need to
look at the the Marshal.PtrToStringXXX methods. You would probably be
able to use Marshal.PtrToStringAuto here though...

Dim className As String = Marshal.PtrToStringAuto (cs.lpszClass)

Anyway, that's what I would do if I understand your question correctly
;)

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
System Up Time: 14 Days, 17 Hours, 26 Minutes, 22 Seconds
Nov 21 '05 #7
Why is it written in the Platform SDK & the .NET Framework SDK that LPCStr
etc are null terminated unicode strings?

Yes, I know about the data types

The original structure states LPCStr & not LPTStr. So, how can you convert
it to T CHAR?
<MarshalAs(UnmanagedType.LPTStr)>
I disagree with what you have used above.

Yesterday, there was a user who asked about converting a function which used
LPCWStr & LPCStr. If you look them up in the data types you'll notice that
they are either declared as System.String or System.StringBuilder
(System.Text.StringBuilder) & handled accordingly.
Nov 21 '05 #8
"Crouchie1998" <Cr**********@discussions.microsoft.com> schrieb:
Why is it written in the Platform SDK & the .NET Framework SDK that LPCStr
etc are null terminated unicode strings?
I didn't find any occurance of 'LPCSTR' in the .NET Framework documentation,
and the Platform SDK documentation (same page as mentioned in my previous
post) says on 'LPCSTR' "Pointer to a constant null-terminated string of
8-bit Windows (ANSI) characters". ANSI, not Unicode!
The original structure states LPCStr & not LPTStr. So, how can you convert
it to T CHAR?
Doesn't it use 'LPCTSTR' (the syntax in the documentation of "'CREATESTRUCT'
Structure" does)?

| LPCTSTR lpszName;
| LPCTSTR lpszClass;
<MarshalAs(UnmanagedType.LPTStr)>
I disagree with what you have used above.


I think that 'LPTStr' is OK. It's not even necessary to specify the
'MarshalAs' attribute if 'CharSet' is specified for the structure containing
the string members:

\\\
<StructLayout(LayoutKind.Auto, CharSet:=CharSet.Auto)> _
Public Structure...
...
End Structure
///

In this case, strings are passed to a function ('CreateWindowEx') and are
not manipulated by this function.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9
hey Tom,

I think you understood what I am trying to do. I am getting an IntPtr
which points to a structure of the window which is about to be created.
This structure contains further information about the window like title,
coordinates etc. My first try converting the given structure to vb.net
looked exactly like yours. But when I read out the values, I always have
0 for x and 96 for the y-value. I'm also getting negative values for
lpszClass and 0 for lpszName. So I think, there is a problem with the
structure.

@Crouchie1998:
If it's easy for you to convert it for me, I'd really appreciate it. I
am somehow stuck at this point.

Thanks.
Nov 21 '05 #10

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

Similar topics

5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
3
by: Brian Henry | last post by:
If i have a structure type and i place the structures data into a tag property (which is an object) it will go in obviously, but when i pull an object back into a structrured type it will error.....
4
by: Clark Stevens | last post by:
I have a program that I'm converting from VB6 to VB.NET. It reads in a text file containing barcode numbers and their corresponding descriptions. Then the user enters the barcode number and the...
4
by: gg9h0st | last post by:
i'm a newbie studying php. i was into array part on tutorial and it says i'll get an array having keys that from member variable's name by converting an object to array. i guessed "i can...
5
by: redeagle | last post by:
In VB6, the code for a structure is Structure zFuheader Dim Id1(80) As Byte Dim Id2(80) As Byte End Structure However, in .NET, it doesn't let you declare the array size in the structure.
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
1
by: Rick Knospler | last post by:
I am trying to convert a vb6 project to vb.net. The conversion worked for the most part except for the fixed length strings and fixed length string arrays. Bascially the vb6 programmer stored all...
2
by: HONOREDANCESTOR | last post by:
I've been converting a dotnet dll to a com object so that it can be called from vb6. If I want to pass a structure to a routine in the com object, like this: Call MyRoutine(byref MyStruct as...
7
helpwithcode
by: helpwithcode | last post by:
Hi people, I am just learning java.I have been creating a project which involves JDBC Connectivity.I find that the statements, String string_dob=text_dob.getText(); //Converting string to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.