I'd like have a file with all of my Win32API stuff in it:
namespace myStuff.Interop Types
{
using HBITMAP = System.IntPtr;
using HWND = System.IntPtr;
public struct POINT
{
public int x;
public int y;
}
}
and then be able to do something like this in another file:
using myStuff.Interop Types;
namespace myStuff.myProje ct
{
[DllImport( "user32.dll " )]
static extern bool SomeFunc( HWND hWnd, HBITMAP hBitmap, POINT point );
[...]
}
which doesn't work since the 'using' aliases from the first file aren't
visible outside that compilation unit. Is there another way to do this?
Michael Roper 6 1339
> namespace myStuff.myProje ct
Not that it matters for the question at hand, but that should instead be
"public class myClass" or some such.
Michael Roper
The only thing I can think of is rather ugly, but it should work, it uses an
implicit conversion, just directly using IntPtr would probably be far
better:
public struct HWND
{
HWND(IntPtr p)
{
ptr = p;
}
System.IntPtr ptr;
public static implicit operator HWND(IntPtr p)
{
return new HWND(p);
}
}
Maybe someone else has a better solution?
"Michael Roper" <mi******@encra ft.com> wrote in message
news:bk******** ****@ID-160215.news.uni-berlin.de... I'd like have a file with all of my Win32API stuff in it:
namespace myStuff.Interop Types { using HBITMAP = System.IntPtr; using HWND = System.IntPtr;
public struct POINT { public int x; public int y; } }
and then be able to do something like this in another file:
using myStuff.Interop Types; namespace myStuff.myProje ct { [DllImport( "user32.dll " )] static extern bool SomeFunc( HWND hWnd, HBITMAP hBitmap, POINT point ); [...] }
which doesn't work since the 'using' aliases from the first file aren't visible outside that compilation unit. Is there another way to do this?
Michael Roper
Daniel O'Connell writes: The only thing I can think of is rather ugly, but it should work, it uses an implicit conversion, just directly using IntPtr would probably be far better:
Thanks Daniel, I'll play with it and see how it looks in IL. You're right
though, it is ugly! Guess I was hoping for a "oh, here's how you do a text
include..."
I guess I don't understand why (since text includes are disallowed) the
"using <namespace>" and especially the "using =" statements can't actually
be compiled into a namespace (you know...so I could do what I want :).
Where's the harm?
Michael Roper
"Michael Roper" <mi******@encra ft.com> wrote in message
news:bk******** ****@ID-160215.news.uni-berlin.de... Daniel O'Connell writes: The only thing I can think of is rather ugly, but it should work, it uses an implicit conversion, just directly using IntPtr would probably be far better: Thanks Daniel, I'll play with it and see how it looks in IL. You're right though, it is ugly! Guess I was hoping for a "oh, here's how you do a
text include..."
I guess I don't understand why (since text includes are disallowed) the "using <namespace>" and especially the "using =" statements can't actually be compiled into a namespace (you know...so I could do what I want :). Where's the harm?
Don't know if there is a specific harm, it just doesn't seem to be an
apparent usage. I don't know if the design team ever even thought that
someone may want to alias a type to another type within a specific
namespace(which , IMHO, is much better than a typedef or #define that applies
globally).
One thing I could see is its a bit confusing. I HATED C\C++ code where I'd
see declarations like this(hopefully correct, its been a while):
typedef DWORD unsigned int;
typedef UINT DWORD;
typedef MYHANDLE UINT;
typedef YOURHANDLE MYHANDLE;
//then to throw some really oddities in, what if they did this?
//is this even allowed...its been so long I can't remember..think it is.
#define YOURHANDLE unsigned char
I would then find a reference to YOURHANDLE somewhere, and not really have a
clue as to what it was. Having an exact type name can save alot of
frustration in the long run. Which is also a good part of why that code I
posted earlier is ugly as well, you still don't really know that HWND is
actually an IntPtr, or if looking at a method without intellisense or the
docs, that the method doesn't take a IntPtr anyway.
Michael Roper
Daniel O'Connell writes: Which is also a good part of why that code I posted earlier is ugly as well, you still don't really know that HWND is actually an IntPtr, or if looking at a method without intellisense or the docs, that the method doesn't take a IntPtr anyway.
Right, that's why I'd have a clear preference for the 'using =' construct if
it worked. It's really nice (especially as an old, old WinAPI guy) to be
able to see my PInvoke imports defined the way I've always used them, and
get the "truth" from Intellisense if I need it.
Michael Roper
"Michael Roper" <mi******@encra ft.com> wrote in message
news:bk******** ****@ID-160215.news.uni-berlin.de... Daniel O'Connell writes: Which is also a good part of why that code I posted earlier is ugly as well, you still don't really know that HWND is actually an IntPtr, or if looking at a method without intellisense or the docs, that the method doesn't take a IntPtr anyway. Right, that's why I'd have a clear preference for the 'using =' construct
if it worked. It's really nice (especially as an old, old WinAPI guy) to be able to see my PInvoke imports defined the way I've always used them, and get the "truth" from Intellisense if I need it.
It seems your options are pretty restricted, I can see that the type is of
use(and this is a situation where I would use hungarian notation, marking
variables with h or hwnd). However, such a feature would probably be abused
commonly for less useful reasons, similarly to how C libs often used extra
typedefs simply to change the name, it got annoying and started to really
get ridiculous Michael Roper
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Reed L. O'Brien |
last post by:
I see rotor was removed for 2.4 and the docs say use an AES module
provided separately... Is there a standard module that works alike or
an AES module that works alike but with better encryption?
cheers,
reed
|
by: Kerberos |
last post by:
I followed Dan Cederholm's image replacement tutorial, to replace a header
tag by a logo. The h1 is clickable if no CSS is applied but it I replace
it by the logo, the area isn't clickable anymore when I pass the mouse
over the logo. Is there a way to replace a link by an image that will
still be clickable?
Thanks,
--
Kerberos.
|
by: Vibha Tripathi |
last post by:
Hi Folks,
I put a Regular Expression question on this list a
couple days ago. I would like to rephrase my question
as below:
In the Python re.sub(regex, replacement, subject)
method/function, I need the second argument
'replacement' to be another regular expression ( not a
string) . So when I find a 'certain kind of string' in
|
by: Paul D. Boyle |
last post by:
Hi all,
There was a recent thread in this group which talked about the
shortcomings of fgets(). I decided to try my hand at writing a
replacement for fgets() using fgetc() and realloc() to read a line of
arbitrary length. I know that the better programmers in this group could
write a more robust function, but here is my shot at it anyway.
I would appreciate people's comments on my fget_line() code below
(usage example included). Any...
|
by: chris |
last post by:
Hallo,
I am in need of a replacement for the Microsoft Visual Studio .NET.
The reason is quiet simple. I develop forms which are used on
different
microsoft windows platform, and one microsoft windows platform spoils
the other microsoft windows platform. For example: I have two
projects, one for pc
and one for pocket pc. I would like (or better I have to) share the
| |
by: lawrence k |
last post by:
Want to replace the limit clause in a query, but can't get it right.
What's wrong with this:
$pattern = "(.*)limit (.*)";
$replacement = '$1';
$replacement .= "LIMIT $limit";
$replacement .= '$2';
$query = preg_replace ($pattern, $replacement, $query);
|
by: woessner |
last post by:
I'm using a C++ compiler on a DSP that doesn't provide the bitset
class. Can anyone suggest a replacement for it? I've written a lot of
code that uses the bitset class (before I knew about the...
inadequacies of the compiler), so it needs to have approximately the
same interface.
Thanks in advance,
Bill
|
by: Roman Mashak |
last post by:
Hello,
I'd like to make a simple replacement of 'pow()' function for the embedded
platform I'm working on. What is the better way, probably bit shifting?
Thanks.
Best regards, Roman Mashak.
|
by: Francogrex |
last post by:
Hi, I'm trying to sample without replacement some numbers (xons:70
values out of 1 to 200 and xEPS1cover:150 values out of 1 to 200).
Then I'm trying to intersect both samples to see how many are in
common. I have tried to write the code below, but I cannot seem to
sample without replacement (there are recurrent numbers within the
same sample, I don't want that) and I cannot either find the exact
intersection between the two samples. Can...
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |