|
Pete O'Hanlon wrote: I have plenty. Millions upon millions of lines of the stuff.
Yeah, but does that contain anything related to Saint George?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hold on while I add a comment.
It does now.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Now is the time to provide an actual answer to the OP then.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Don't forget to include this reference[^].
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
|
dataminers wrote: georgian calendar
Don't know about this. Know something about Gregorian and Julian calendars.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
Hi all,
I have written a C++ library which communicates with an external device. The device sends back certain X and Y coordinates. I am trying to send back these X and Y coordinates to a calling c# application, but I don't want to poll the library with a thread or a loop. Is there a way I can create an event in the C++ library and register to it from the c# application, so that when the X and Y coordinates have values, the event will be fired in the c# application?
Many thanks in advance.
Kind regards,
|
|
|
|
|
I assume you are using P/Invoke; if you somehow get a signal (such as an interrupt) in your native code, all you need is a way to call a managed method; this is known as a callback. You can see an example in this article[^].
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi Luc,
Thanks for the reply. I have heard about P/Invoke, but wasn't sure about how to go about using it. But many thanks for the link, I think the delegate section is what I needed.
Kind regards,
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi Luc,
After some testing, I found myself back at square one, reason being that the example does not illustrate what happens within the c++ section of the code. The author makes use of standard windows methods and I have no idea what they are doing in the method. More specifically, the EnumWindows method. I must create my own method so that I can receive the X and Y coordinates (and that is what the CALLBACK is for ... i guess), thus what parameters must I send to the c++ method? I apologize for my ignorance but I'm in the dark here
C++ Section
BOOL EnumWindows(
WNDENUMPROC lpEnumFunc,
LPARAM lParam
);
BOOL CALLBACK EnumWindowsProc(
HWND hwnd,
LPARAM lParam
);
BOOL IsWindowVisible(
HWND hWnd
);
C# Section
class DelegateExample {
private List<IntPtr> windowList;
public List<IntPtr> GetVisibleWindowHandles() {
windowList=new List<IntPtr>();
EnumWindows(new EnumWindowsProc(CollectVisibleWindows), IntPtr.Zero);
Console.WriteLine("There are {0} visible windows", windowList.Count);
return windowList;
}
private bool CollectVisibleWindows(IntPtr hWnd, IntPtr lParam) {
if(IsWindowVisible(hWnd)) windowList.Add(hWnd);
return true;
}
[DllImport("user32.dll")]
private static extern int EnumWindows(LP_EnumWindowsProc ewp, IntPtr lParam);
private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
[DllImport("user32.dll")]
private static extern bool IsWindowVisible(IntPtr hWnd);
}
Many thanks in advance.
Kind regards,
|
|
|
|
|
OK, it seems you are having two problems:
1.
you don't want to poll, i.e. periodically read and process the data. You want something that is event driven, a cause-and-effect kind of thing. That is possible if and only if your peripheral is giving you a cause, maybe by issuing an interrupt; or by sending data. If not, all you can do is have a polling loop.
2.
Calling managed code from unmanaged code, is called a callback. There are at least two examples in my article, the more informative one may well be the "Two-side logging" which includes all the code involved for both parties.
Hope that helps.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Thanks again Luc.
P.s the demo application link does not work.
Kind regards,
|
|
|
|
|
Programm3r wrote: link does not work
You're right, that is one of the reasons it still is Work In Progress. However, the relevant stuff is in the article itself.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
with Microsoft.Win32.SafeHandles.SafeWaitHandle you can use C++ Handles in C#. -> AutoResetEvent
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Hi Karsten,
Could you please elaborate on your answer?
Many thanks.
Kind regards,
|
|
|
|
|
Yesterday, I tried to convert an Icon consists of single PNG image into a Bitmap with Icon.ToBitmap() method. But it threw a mysterious ArgumentOutOfRangeException.
I've investigated the cause of the error, and reached a conclusion. The method doesn't assume that the icons may contain PNG images.
Is it a bug of .NET framework?
|
|
|
|
|
No. It's a misunderstanding on your part of what an icon is.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Sorry, I can't understand what you said.
You mean an icon which contains bitmaps in PNG format is incorrent one?
|
|
|
|
|
It means that even though the (png) image is being used as an icon, it is not in the Icon image format (*.ico). It is just a bitmap and you do not need to convert it to load it into a bitmap. Treat it exactly the same as you would a *.bmp file.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
mmm... I'm still not convinced.
This is head 48 bytes of my .ico file.
0x0000: 00 00 01 00 01 00 00 00 00 00 01 00 20 00 d2 d9
0x0010: 00 00 16 00 00 00 89 50 4e 47 0d 0a 1a 0a 00 00
0x0020: 00 0d 49 48 44 52 00 00 01 00 00 00 01 00 08 06
This has correct ICONDIR, CONDIRENTRY and PNG image after them. It's not a renamed PNG file.
It's a correct icon, isn't it?
|
|
|
|
|
Unfortunately, I am not familiar enough with the various image formats to identify that as a 'correct' header or not. It may be that the image was produced by a program that doesn't quite match with what the converter was expecting, and there are loads of those around.
You might try loading it into one of the many Icon Editor programs and, if it loads OK, do a Save As, then try your routine again with the copy.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
No. I would call it a "special feature".
conclusion: sh*t happens
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
There is most definitely a bug in the .Net framework, as explained by Paulo Santos[^]. Sorry if the link breaks later, but it only seems to have survived in the Google cache.
The short of it is that the Icon class calls the Win API function CreateIconFromResourceEx to extract the appropriately sized image from the .ico file with the wrong parameters, resulting in it always loading the closest match to a 32x32 image it can find. Paulo does explain a way to force it to load a 256x256 vista icon image, however he also discovered that .png images incorrectly register their size in the .ico file as 0x0 pixels.
So, with only one .png in the .ico file it will always be loaded, but the size recorded in the Icon object will never match. Consequently a subsequent call to Icon.ToBitMap will attempt to re-load the wrong size image from the .ico file and will promptly crash with an ArgumentOutOfRangeException !
The solution is, don't use .png images in icons. Or if you do then make sure you also include a 32x32 pixel .bmp image.
Alternatively, wait for a bug fix from Microsoft, but don't hold your breath.
|
|
|
|
|
Excellent answer!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|