473,405 Members | 2,185 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,405 software developers and data experts.

Why am I still using win32API calls?

ian
Hi, I keep resorting to com interop calls, for example I needed the
location of the carot in a text box and I had to use a win32API call
(GetCarotPos??) to do that.
It's one example, I could give several more that have come up over the
last few months, and it has raised a couple of questions the answers to
which could plug a few holes in my knowledge.

First, I'm uncomfortable using API calls purely because I don't fully
understand the implications regarding security settings and so forth. Is
there anything I need to do to make my assemblies safe?

I'm a little unsure about how the standard controls were developed. Can
I assume the framework is using OS calls to draw the carot, thus making
GetCarotPos(sp?) work?

I know the framework grows with each version, can we expect to see some
of these things incorporated? Do the vista extensions to the framework
address any of these issues?

Apologies if that's vague. These issues don't affect me so much
professionally, only when I try and do fun stuff at home, so I'm not as
clued up as I could be.

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Jun 13 '06 #1
6 1544
ian wrote:
Hi, I keep resorting to com interop calls, for example I needed the
location of the carot in a text box and I had to use a win32API call
(GetCarotPos??) to do that.
I'd be curious as to why you need to know the carots position in the
first place. I don't think i've ever had this particular need come up.
It's one example, I could give several more that have come up over the
last few months, and it has raised a couple of questions the answers to
which could plug a few holes in my knowledge.
How many is several?
First, I'm uncomfortable using API calls purely because I don't fully
understand the implications regarding security settings and so forth. Is
there anything I need to do to make my assemblies safe?
Your assemblies are safe; to execute the COM call, I think they need
full trust. But I'm not sure you have anything to worry about calling
API.
I'm a little unsure about how the standard controls were developed. Can
I assume the framework is using OS calls to draw the carot, thus making
GetCarotPos(sp?) work?
Likely the framework is calling the API for you. So your API call to
get the carot should be safe.
I know the framework grows with each version, can we expect to see some
of these things incorporated? Do the vista extensions to the framework
address any of these issues?


Its commonly held that .Net is meant to replace the current Win32 API,
and will in time become the prefered way to 'make kenel calls.' So I
imagine that the framework would continue to expose more and more.

Regarding Vista, there's WPF pretty much replaces the
System.Windows.Forms namespace (although even with the extensions, I
think you can use either). As the framework gets larger, the need for
API calls should decrease even more (although I have to admin, I rarely
need to call the Win32 API as it is).

If you're building in pure .Net and still making lots of API calls, I'd
rethink what I was trying to do.

Andy

Jun 13 '06 #2
Hi ian,

I can certainly understand your difficulty. The .Net CLR is one huge mother,
and you may not find what you're looking for, simply because it doesn't have
a similar name to a WinAPI call. For example, you can find the position of
the caret in a TextBox by invoking the SelectionStart property of the
TextBox, which returns the character position of the caret. Unless, of
course, you're actually wanting to get the XY coordinates of the caret,
which is not as common a task. In that case, you would certainly have to use
the WinAPI call, which is perfectly acceptable if you need to.
Is there anything I need to do to make my assemblies safe?
Here are some general references:

http://msdn2.microsoft.com/en-us/lib...3k(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/26thfadc.aspx
http://msdn2.microsoft.com/en-us/library/0h9e9t7d.aspx
http://msdn2.microsoft.com/en-us/library/fzhhdwae.aspx
http://msdn2.microsoft.com/en-us/lib...se(VS.80).aspx

WinAPI functions are native C++. Data is marshalled, and synchronized across
the different processes, and therefore, is not actually the same data, even
though the Platform does a nice job of making it seem that way. So, there
are some situations in which you need to be careful about freeing unmanaged
memory, which is handled better when doing Interop with COM. The following
(and related) article deals with the potential issues that can arise:

http://msdn2.microsoft.com/en-us/library/f1cf4kkz.aspx

Also check out the article on Blittable vs. Non-Blittable types:

http://msdn2.microsoft.com/en-us/library/75dwhxf7.aspx

If you call unmanged functions that work with pointers, either by receiving
or returning them, check out the following article on Copying and Pinning:

http://msdn2.microsoft.com/en-us/library/23acw07k.aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

A lifetime is made up of
Lots of short moments.
"ian" <no****@devdex.com> wrote in message
news:OZ****************@TK2MSFTNGP04.phx.gbl... Hi, I keep resorting to com interop calls, for example I needed the
location of the carot in a text box and I had to use a win32API call
(GetCarotPos??) to do that.
It's one example, I could give several more that have come up over the
last few months, and it has raised a couple of questions the answers to
which could plug a few holes in my knowledge.

First, I'm uncomfortable using API calls purely because I don't fully
understand the implications regarding security settings and so forth. Is
there anything I need to do to make my assemblies safe?

I'm a little unsure about how the standard controls were developed. Can
I assume the framework is using OS calls to draw the carot, thus making
GetCarotPos(sp?) work?

I know the framework grows with each version, can we expect to see some
of these things incorporated? Do the vista extensions to the framework
address any of these issues?

Apologies if that's vague. These issues don't affect me so much
professionally, only when I try and do fun stuff at home, so I'm not as
clued up as I could be.

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***

Jun 13 '06 #3
ian <no****@devdex.com> wrote in
news:OZ**************@TK2MSFTNGP04.phx.gbl:
I'm a little unsure about how the standard controls were
developed. Can I assume the framework is using OS calls to draw
the carot, thus making GetCarotPos(sp?) work?


Ian,

You can interactively view the decompiled source code of any .Net
assembly (including the framework assemblies) using Reflector
(http://www.aisto.com/roeder/dotnet/). This utility allows you to
view the decompiled code in VB.Net, C#, IL, C++ and Delphi for .Net.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Jun 13 '06 #4
ian
Thank you all, that answers my questions perfectly.

Andy: Some of the things I've been after include global keyboard hooks
and enumerating visible windows (I have two third party app's that have
disabled the minimise button for no good reason! I was duplicating an
old vb6 app which finds the window then sends a showwindow minimised to
it.)

Kevin: Great resources, thanks for the links. I was after the pixel
position of the carot. I was duplicating intellisense in reverse,
displaying tentative results for a parser in a control that tracks the
carot. Bit wierd I know, but it's for a fun project :) I had this idea
of parsing a formula, say x=y and then showing a mini version of the
results, in this case a mini graph with a diagonal line, just below the
formula as you type. If that's not been done before, consider this prior
art and therefore free for all less my 10pc :)

Chris: Another great resource, many thanks for your time and assistance.

Cheers
Ian


*** Sent via Developersdex http://www.developersdex.com ***
Jun 13 '06 #5
Hi Ian,

You're idea of fun is right up my alley!

I understand you've been wanting to implement some global hooks. I have a
couple of favorites for this in .Net:

http://www.codeproject.com/csharp/globalsystemhook.asp
http://www.codeproject.com/csharp/NetWin32Hooks.asp

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

A lifetime is made up of
Lots of short moments.

"ian" <no****@devdex.com> wrote in message
news:eZ**************@TK2MSFTNGP02.phx.gbl...
Thank you all, that answers my questions perfectly.

Andy: Some of the things I've been after include global keyboard hooks
and enumerating visible windows (I have two third party app's that have
disabled the minimise button for no good reason! I was duplicating an
old vb6 app which finds the window then sends a showwindow minimised to
it.)

Kevin: Great resources, thanks for the links. I was after the pixel
position of the carot. I was duplicating intellisense in reverse,
displaying tentative results for a parser in a control that tracks the
carot. Bit wierd I know, but it's for a fun project :) I had this idea
of parsing a formula, say x=y and then showing a mini version of the
results, in this case a mini graph with a diagonal line, just below the
formula as you type. If that's not been done before, consider this prior
art and therefore free for all less my 10pc :)

Chris: Another great resource, many thanks for your time and assistance.

Cheers
Ian


*** Sent via Developersdex http://www.developersdex.com ***

Jun 14 '06 #6
ian,
| Hi, I keep resorting to com interop calls, for example I needed the
| location of the carot in a text box and I had to use a win32API call
| (GetCarotPos??) to do that.
I would use TextBoxBase.SelectionStart to get (or set) the carot pos in a
text box. Rather then going for an API right away.
There are a handful of Win32 to .NET cross references available:

http://msdn.microsoft.com/library/de...l/win32map.asp

Unforutnately they are incomplete; also I'm not seeing a .NET 2.0 version
available right now.

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"ian" <no****@devdex.com> wrote in message
news:OZ****************@TK2MSFTNGP04.phx.gbl...
| Hi, I keep resorting to com interop calls, for example I needed the
| location of the carot in a text box and I had to use a win32API call
| (GetCarotPos??) to do that.
| It's one example, I could give several more that have come up over the
| last few months, and it has raised a couple of questions the answers to
| which could plug a few holes in my knowledge.
|
| First, I'm uncomfortable using API calls purely because I don't fully
| understand the implications regarding security settings and so forth. Is
| there anything I need to do to make my assemblies safe?
|
| I'm a little unsure about how the standard controls were developed. Can
| I assume the framework is using OS calls to draw the carot, thus making
| GetCarotPos(sp?) work?
|
| I know the framework grows with each version, can we expect to see some
| of these things incorporated? Do the vista extensions to the framework
| address any of these issues?
|
| Apologies if that's vague. These issues don't affect me so much
| professionally, only when I try and do fun stuff at home, so I'm not as
| clued up as I could be.
|
| Thanks.
|
|
|
|
|
| *** Sent via Developersdex http://www.developersdex.com ***
Jun 19 '06 #7

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

Similar topics

3
by: Matt Smith | last post by:
hi all, again.... having another problem with python COMs, I run a python script on a win2000 machine, that uses win32com.client and it runs perfectly, whereas when I come to run it on a win98...
1
by: arN | last post by:
Hi ! I'm a Java developper and I wish to make a capture of an offscreen window (on WinXP). It's not possible in Java, so I use a python script and WM_PRINT, but it doesn't seem to work. Could...
3
by: Ian Rowland | last post by:
Is there a way, using managed code, to determine the Service Pack of the OS without resorting to registry calls? OSVersion doesn't give this information. It seems the only way is to use the...
5
by: Mark Overstreet | last post by:
I am trying to click a button in another window and I have it's hWnd value so I was trying to use Send message. Here is my code but it doesn't work as expected... response =...
4
by: rbt | last post by:
Can someone detail the differences between these two? On Windows which is preferred? Also, is it true that win32api.DeleteFile() can remove the 'special' files located in the 'special' folders...
2
by: Jim | last post by:
I am trying to figure out how to embed Python in a little C++ Windows console app. Here's the code: // Py_Initialize(); Py_InitializeEx(0); PyRun_SimpleString("from win32com.client import *");...
0
by: Mike | last post by:
Hi. I have Python 2.4 installed on my local machine in c:\Python24. I have also downloaded the python for windows extensions installer pywin32-208.win32-py2.4.exe and installed this to...
2
by: ti | last post by:
Hello all, Does anyone have any idea that how to use GetLogicalProcessorInformation, win32api, under using csharp? http://msdn2.microsoft.com/en-us/library/ms683194.aspx For me, one of the...
1
by: Michiel Overtoom | last post by:
On Saturday 19 July 2008 21:13:04 Lamonte Harris wrote: What are the actions you do and the commands you give, and what is the precise error you get? Greetings, -- "The ability of the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...

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.