473,473 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

GetClassName


Hi,

Declare Ansi Function GetClassName Lib "user32" Alias "GetClassNameA"
( ByVal hWnd As IntPtr, ByVal lpClassName As System.Text.StringBuilder,
ByVal nMaxCount As Int32) As Int32

I am trying go use GetClassName API to get the class name, but I don't know
how to pass IntPtr.
I'll appreciate your help.

Thanks in advance.
Kartic


Nov 20 '05 #1
4 16663
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA"
(ByVal hwnd As Int32, ByVal lpClassName As String, ByVal nMaxCount As
Int32) As Int32
afaik there is no such thing as a IntPtr in .net. You will have to pass
it as the type of variable that is required by the api. In this case it
is an int32.

Kartic wrote:
Hi,

Declare Ansi Function GetClassName Lib "user32" Alias "GetClassNameA"
( ByVal hWnd As IntPtr, ByVal lpClassName As System.Text.StringBuilder,
ByVal nMaxCount As Int32) As Int32

I am trying go use GetClassName API to get the class name, but I don't know
how to pass IntPtr.
I'll appreciate your help.

Thanks in advance.
Kartic


Nov 20 '05 #2
In article <OF**************@TK2MSFTNGP10.phx.gbl>, Kartic wrote:

Hi,

Declare Ansi Function GetClassName Lib "user32" Alias "GetClassNameA"
( ByVal hWnd As IntPtr, ByVal lpClassName As System.Text.StringBuilder,
ByVal nMaxCount As Int32) As Int32

I would delcare this more like:

Declare Auto Function GetClassName Lib "user32" _
(ByVal hWnd As IntPtr, _
ByVal lpClassName As System.Text.StringBuilder, _
ByVal nMaxCount As Integer) As Integer
This way you let the runtime call the appropriate function based on the
platfrom - which can make a difference on NT systems, since you cut out
a lot of Ansi->unicode, Unicode -> Ansi conversions.
I am trying go use GetClassName API to get the class name, but I don't know
how to pass IntPtr.
I'll appreciate your help.


Well, the IntPtr is the handle of the window your trying to get the
class name of... So, if your trying to get the class name of the
current form:

Dim className As New StringBuidler(255)

GetClassName(Me.Handle, className, className.Capacity)

Return className.ToString()

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #3
In article <u#**************@TK2MSFTNGP09.phx.gbl>, Shawn D Shelton wrote:
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA"
(ByVal hwnd As Int32, ByVal lpClassName As String, ByVal nMaxCount As
Int32) As Int32

Acutally, it would probably be better to drop the alias and use the Auto
modifier:

Private Declare Auto Function GetClassName Lib "user32" _
(ByVal hWnd As IntPtr, _
ByVal lpClassName As System.Text.StringBuilder, _
ByVal nMaxCount As Integer) As Integer

Also, notice I changed the string to stringbuilder. You should never
pass strings that are intended to be modified by the caller. It equates
to a large amount of overhead for the marshaller. It is preferable to
use System.Text.StringBuilder because it is a mutable buffer.

afaik there is no such thing as a IntPtr in .net. You will have to pass
it as the type of variable that is required by the api. In this case it
is an int32.


System.IntPtr. It should be used for all handle types - including
hWnds - when doing P/Invoke.

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #4
* "Kartic" <kg****@csystemssoftware.com> scripsit:
Declare Ansi Function GetClassName Lib "user32" Alias "GetClassNameA"
( ByVal hWnd As IntPtr, ByVal lpClassName As System.Text.StringBuilder,
ByVal nMaxCount As Int32) As Int32
Why do you declare the function as 'Ansi'? Declare it as 'Auto' and
remove the alias ('Alias...').
I am trying go use GetClassName API to get the class name, but I don't know
how to pass IntPtr.


\\\
n = GetClassName(Me.Handle, ..., ...)
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

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

Similar topics

7
by: Shuttermutt | last post by:
Okay, I'm a relative newcomer to object-oriented PHP, but no stranger to OOP in general. I've spent the last three hours trying to figure out why this code snipped doesn't do what I expect it to: ...
2
by: bala | last post by:
Hi, I want to know how to getclassname of application from python..In python There is no method like GetClassName... Is there any other Method ...I kindly give some example in python.. If anyone...
2
by: Scott Manson | last post by:
StringBuilder bldr=new StringBuilder(); int res=GetClassName(0x00240110,bldr,255); Debug.WriteLine(bldr.ToString()); if(bldr.ToString()=="AfxFrameOrView42s") Debug.Write("Things SHOULD work");...
1
by: Andreas Poller | last post by:
Hello, I have the following problem: I have a class deriving from ICustomTypeDescriptor: public __gc class TPropertyBag : public ICustomTypeDescriptor { private: ...
5
by: Lance | last post by:
I want to expose properties of a class to a user via a PropertyGrid class. Some of the properties are of type System.IO.FileInfo. Ideally, an OpenFileDialog window would appear when the user...
3
by: Benjamin GILLET | last post by:
Dear all, I have coded a class called Object with a member method called getClassName(). Here is the code of this class: #include <iostream>
2
by: stephen.garner | last post by:
Hi, I am using the IntPtr FindWindow(string lpClassName, string lpWindowName); to get the handle for a window (notepad in this case), I am then using int GetClassName(IntPtr hWnd, out...
59
by: peter.tornqvist | last post by:
Maybe I'm stupid or maybe I am missing the obvious, but I can't find a way to define a type alias in C# for primitive types (class and interfaces I can inherit from, no problem). I.e I want to...
5
by: Simon Woods | last post by:
Hi Still trying to get to grips with VB.Net so sorry if these seem silly questions ... I have an object which is implementing a secondary interface. I want to get the name of the underlying...
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...
0
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
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
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
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...
0
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,...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.