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

Does anyone know what is wrong with these imports from User32.dll?

The constants.windowLongIndices type is an enum. That is there so I can
ensure the appropriate values are always used. Since I had to replace the
GWL macros with new values, I decided to prevent passing 7 -- or whatever
the author of the caller felt like. I tried both ExactSpelling=true and
setting the entry point manually. I also tried forcing the Unicode and
ASCII versions. (According to the Win32 documentation, both functions have
UNICODE versions in NT/2000/XP. My tests are on a XP Pro SP1 system.
[System.Runtime.InteropServices.DllImport("user32", SetLastError=true)]
public static extern IntPtr SetWindowLongPtr(IntPtr hWnd,
constants.windowLongIndices index, IntPtr iNewValue);

[System.Runtime.InteropServices.DllImport("user32", SetLastError=true)]
public static extern IntPtr GetWindowLongPtr(IntPtr hWnd,
constants.windowLongIndices index);

----------
Will Pittenger
E-Mail: mailto:wi************@verizon.net
All mail filtered by Qurb (www.qurb.com)
Nov 16 '05 #1
5 1480
Hello Will,

Try

public static extern IntPtr SetWindowLongPtrW(IntPtr hWnd,
constants.windowLongIndices index, IntPtr iNewValue);

and specify the ExactSpelling option. You can also apply
the MarshalAs attribute to the "index" argument to ensure
it is indeed treated as an int32 type parameter.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Will Pittenger" <wi************@verizon.net> wrote in message
news:uy*************@tk2msftngp13.phx.gbl...
The constants.windowLongIndices type is an enum. That is there so I can
ensure the appropriate values are always used. Since I had to replace the
GWL macros with new values, I decided to prevent passing 7 -- or whatever
the author of the caller felt like. I tried both ExactSpelling=true and
setting the entry point manually. I also tried forcing the Unicode and
ASCII versions. (According to the Win32 documentation, both functions have UNICODE versions in NT/2000/XP. My tests are on a XP Pro SP1 system.
[System.Runtime.InteropServices.DllImport("user32", SetLastError=true)]
public static extern IntPtr SetWindowLongPtr(IntPtr hWnd,
constants.windowLongIndices index, IntPtr iNewValue);

[System.Runtime.InteropServices.DllImport("user32", SetLastError=true)]
public static extern IntPtr GetWindowLongPtr(IntPtr hWnd,
constants.windowLongIndices index);

----------
Will Pittenger
E-Mail: mailto:wi************@verizon.net
All mail filtered by Qurb (www.qurb.com)


Nov 16 '05 #2
Will,

On Win32, SetWindowLongPtr is implemented as a macro that just calls
the old SetWindowLong function (and the same is true for
GetWindowLong/Ptr). So you have to specify that as your entry point

[DllImport("user32", SetLastError=true, EntryPoint="SetWindowLong",
CharSet=CharSet.Auto)]
public static extern IntPtr SetWindowLongPtr(IntPtr hWnd,
constants.windowLongIndices index, IntPtr iNewValue);

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #3
Gosh, how could I forget this old trick! So, as an additional advice to the
original poster: if you have Platform SDK installed, you can investigate the
corresponding API declaration in the Windows header files to ensure given
API function is not actually a macro or something.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
Will,

On Win32, SetWindowLongPtr is implemented as a macro that just calls
the old SetWindowLong function (and the same is true for
GetWindowLong/Ptr). So you have to specify that as your entry point

[DllImport("user32", SetLastError=true, EntryPoint="SetWindowLong",
CharSet=CharSet.Auto)]
public static extern IntPtr SetWindowLongPtr(IntPtr hWnd,
constants.windowLongIndices index, IntPtr iNewValue);

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Nov 16 '05 #4
I think that Mattias had the better answer.

----------
Will Pittenger
E-Mail: mailto:wi************@verizon.net
All mail filtered by Qurb (www.qurb.com)
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:uF****************@tk2msftngp13.phx.gbl...
Hello Will,

Try

public static extern IntPtr SetWindowLongPtrW(IntPtr hWnd,
constants.windowLongIndices index, IntPtr iNewValue);

and specify the ExactSpelling option. You can also apply
the MarshalAs attribute to the "index" argument to ensure
it is indeed treated as an int32 type parameter.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Will Pittenger" <wi************@verizon.net> wrote in message
news:uy*************@tk2msftngp13.phx.gbl...
The constants.windowLongIndices type is an enum. That is there so I can
ensure the appropriate values are always used. Since I had to replace the GWL macros with new values, I decided to prevent passing 7 -- or whatever the author of the caller felt like. I tried both ExactSpelling=true and
setting the entry point manually. I also tried forcing the Unicode and
ASCII versions. (According to the Win32 documentation, both functions

have
UNICODE versions in NT/2000/XP. My tests are on a XP Pro SP1 system.
[System.Runtime.InteropServices.DllImport("user32", SetLastError=true)]
public static extern IntPtr SetWindowLongPtr(IntPtr hWnd,
constants.windowLongIndices index, IntPtr iNewValue);

[System.Runtime.InteropServices.DllImport("user32", SetLastError=true)]
public static extern IntPtr GetWindowLongPtr(IntPtr hWnd,
constants.windowLongIndices index);

----------
Will Pittenger
E-Mail: mailto:wi************@verizon.net
All mail filtered by Qurb (www.qurb.com)

Nov 16 '05 #5
That turns out to be correct. Given that we are supposed to take
precautions to ensure portablity to 64-bit code, how should this be
imported?

----------
Will Pittenger
E-Mail: mailto:wi************@verizon.net
All mail filtered by Qurb (www.qurb.com)
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
Will,

On Win32, SetWindowLongPtr is implemented as a macro that just calls
the old SetWindowLong function (and the same is true for
GetWindowLong/Ptr). So you have to specify that as your entry point

[DllImport("user32", SetLastError=true, EntryPoint="SetWindowLong",
CharSet=CharSet.Auto)]
public static extern IntPtr SetWindowLongPtr(IntPtr hWnd,
constants.windowLongIndices index, IntPtr iNewValue);

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 16 '05 #6

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

Similar topics

2
by: zapazap | last post by:
Dear Snake Charming Gurus, (Was: http://mail.python.org/pipermail/python-list/2004-January/204454.html) First, a thank you to Tim Golden, Thomas Heller, and Mark Hammond for your earlier help...
11
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
11
by: Nick | last post by:
This is really starting to piss me off. Someone please prove me wrong. Here is a link to the function in DX 9 sdk....
1
by: smith | last post by:
I was recently set to release an app that used very common single instance code and hit the oddest issue. After many hours of full build tests I believe that it is duplicatable. Environment: ...
29
by: Vol | last post by:
I think 'atan' can get the angle but it is not the four quadrant angle. Is there any function that i can get the angle from -pi to pi? or I have to use some if ... else? I know in Matlab, we use...
9
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT...
45
by: salad | last post by:
I'm curious about your opinion on setting relationships. When I designed my first app in Access I'd go to Tools/Relationships and set the relationships. Over time I'd go into the window and see...
3
by: Mike Owen | last post by:
Hi, I have set up a new web site application in VS 2005, and have created a couple of pages which seem to run ok. I then manually added a file called Global.asax.vb, within a folder that I...
71
by: active | last post by:
In the main program I check to see if a certain form has been disposed. Does it make sense in that form's FormClosed event to do: Me.Dispose to make sure it is disposed the next time I check. Or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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,...

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.