?
Solved

How do I caste a char to an intptr in VS2005, VB.net

Posted on 2007-10-16
6
Medium Priority
?
838 Views
Last Modified: 2013-11-26
I have the following call in VB.net (VS2005)

Win32Api.PostMessage(HWnd, 258, CType(key, IntPtr), IntPtr.Zero)

this is a send key call (message 258): How do I caste the key (a character) to the intptr type that the call wants?
0
Comment
Question by:Christopher Schene
  • 3
  • 2
6 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 20086166
Have you tried just passing the ASCII value as an integer in this field?  
0
 

Author Comment

by:Christopher Schene
ID: 20086303
That is not an integer, it is an intptr and I am looking for a way to convert from an ASCII value (or integer) to an inptr in VB.net. That is what the function requires: just having an integer does not help
0
 
LVL 41

Expert Comment

by:graye
ID: 20087499
This is a fairly common problem dealing with API calls.   The problem is that there may be many forms of the API declaration.  For example, one form takes a IntPtr as the 3rd parameter, and another form takes an Integer.

So, the fix is to create another "Declare statement" for the PostMessage API that accepts a UInt value as the 3rd parameter.

Private Declare Auto Function PostMessage2 Lib "user32" ( _
ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As IntPtr) As Boolean
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Christopher Schene
ID: 20089533
I am not sure I have the correct idea. I tried

 Private Declare Auto Function PostMessage2 Lib "user32" ( _
                    ByVal hWnd As IntPtr, _
                    ByVal Msg As Integer, _
                    ByVal wParam As UInteger, _
                    ByVal lParam As IntPtr) As Boolean

and I got an exception

ex.Message = "Unable to find an entry point named 'PostMessage2' in DLL 'user32'."

How do I find the one that has the parameter match I need?
0
 
LVL 41

Accepted Solution

by:
graye earned 1000 total points
ID: 20089670
Yeah, you're right...sorry I left off the alias.   Actually you might not need 2 forms of the PostMessage API declaration... if this is the only place where you  use it, then you could just replace the original declaration without the use of a Alias (ie. use PostMessage instead of PostMessage2)

 Private Declare Auto Function PostMessage2 Lib "user32" Alias "PostMessage" ( _
                    ByVal hWnd As IntPtr, _
                    ByVal Msg As Integer, _
                    ByVal wParam As UInteger, _
                    ByVal lParam As IntPtr) As Boolean

Afterwards, you'd use it like this:

    PostMessage2(HWnd, 258, Asc(key), IntPtr.Zero)


0
 

Author Comment

by:Christopher Schene
ID: 20090041
worked great. Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
No other job is as rewarding and demanding as building an iPhone app is. It is not really in the hands of the developer for the success of an iPhone app. Many factors operate jointly for every iOS application's success in the market.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Simple Linear Regression

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question