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

P/Invoke problem

Hi folks,

I have some serious problems with one of the API calls ...

I try to use :

[DllImport("oleacc.dll",CharSet=CharSet.Auto)]
public static extern long AccessibleObjectFromWindow (
long hwnd,
long dwId,
[MarshalAs(UnmanagedType.Struct)]UUID riid,
[MarshalAs(UnmanagedType.Interface)]object ppvObject);

public struct UUID
{
public long Data1;
public int Data2;
public int Data3;
[MarshalAs(UnmanagedType.ByValArray,SizeConst=8)]
public byte[] Data4;
}
public static void TestAA()
{
UUID uid;
uid.Data1 = (long)0x618736e0;
uid.Data2 = (int)0x3c3d;
uid.Data3 = (int)0x11cf;
uid.Data4 = new Byte[8];
uid.Data4[0] = (byte)0x81;
uid.Data4[1] = (byte)0x0c;
uid.Data4[2] = (byte)0x00;
uid.Data4[3] = (byte)0xaa;
uid.Data4[4] = (byte)0x00;
uid.Data4[5] = (byte)0x38;
uid.Data4[6] = (byte)0x9b;
uid.Data4[7] = (byte)0x71;

IAccessible accObj = null;

long ret = AccessibleObjectFromWindow
(wHandle,OBJID_WINDOW,uid,accObj);

but always get a E_INVALIDARG return value.

I also tried

[DllImport("oleacc.dll",CharSet=CharSet.Auto)]
public static extern long AccessibleObjectFromWindow (
long hwnd,
long dwId,
[MarshalAs(UnmanagedType.Struct)]UUID riid,
[MarshalAs(UnmanagedType.AsAny)]object ppvObject);
could someone give me a hint where I make my mistake ?

thx :)

Sven

Nov 15 '05 #1
4 6441
Hint .... long is 64 bit in .NET

Willy.

"Sven Gnagi" <Sv*******@hotmail.com> wrote in message
news:0b****************************@phx.gbl...
Hi folks,

I have some serious problems with one of the API calls ...

I try to use :

[DllImport("oleacc.dll",CharSet=CharSet.Auto)]
public static extern long AccessibleObjectFromWindow (
long hwnd,
long dwId,
[MarshalAs(UnmanagedType.Struct)]UUID riid,
[MarshalAs(UnmanagedType.Interface)]object ppvObject);

public struct UUID
{
public long Data1;
public int Data2;
public int Data3;
[MarshalAs(UnmanagedType.ByValArray,SizeConst=8)]
public byte[] Data4;
}
public static void TestAA()
{
UUID uid;
uid.Data1 = (long)0x618736e0;
uid.Data2 = (int)0x3c3d;
uid.Data3 = (int)0x11cf;
uid.Data4 = new Byte[8];
uid.Data4[0] = (byte)0x81;
uid.Data4[1] = (byte)0x0c;
uid.Data4[2] = (byte)0x00;
uid.Data4[3] = (byte)0xaa;
uid.Data4[4] = (byte)0x00;
uid.Data4[5] = (byte)0x38;
uid.Data4[6] = (byte)0x9b;
uid.Data4[7] = (byte)0x71;

IAccessible accObj = null;

long ret = AccessibleObjectFromWindow
(wHandle,OBJID_WINDOW,uid,accObj);

but always get a E_INVALIDARG return value.

I also tried

[DllImport("oleacc.dll",CharSet=CharSet.Auto)]
public static extern long AccessibleObjectFromWindow (
long hwnd,
long dwId,
[MarshalAs(UnmanagedType.Struct)]UUID riid,
[MarshalAs(UnmanagedType.AsAny)]object ppvObject);
could someone give me a hint where I make my mistake ?

thx :)

Sven

Nov 15 '05 #2
Sven,
[DllImport("oleacc.dll",CharSet=CharSet.Auto)]
public static extern long AccessibleObjectFromWindow (
long hwnd,
long dwId,
[MarshalAs(UnmanagedType.Struct)]UUID riid,
[MarshalAs(UnmanagedType.Interface)]object ppvObject);


I would declare it as

[DllImport("oleacc.dll", PreserveSig=false)]
[return: MarshalAs(UnmanagedType.Interface)]
public static extern object AccessibleObjectFromWindow (
IntPtr hwnd,
uint dwId,
ref Guid riid);

And call it with

Guid uid = new Guid("618736e0-3c3d-11cf-810c-00aa00389b71");
IAccessible accObj = (IAccessible)AccessibleObjectFromWindow(wHandle,
OBJID_WINDOW, ref uid);

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #3
-----Original Message-----
Sven,
[DllImport("oleacc.dll",CharSet=CharSet.Auto)]
public static extern long AccessibleObjectFromWindow (
long hwnd,
long dwId,
[MarshalAs(UnmanagedType.Struct)]UUID riid,
[MarshalAs(UnmanagedType.Interface)]object ppvObject);
I would declare it as

[DllImport("oleacc.dll", PreserveSig=false)]
[return: MarshalAs(UnmanagedType.Interface)]
public static extern object AccessibleObjectFromWindow (
IntPtr hwnd,
uint dwId,
ref Guid riid);

And call it with

Guid uid = new Guid("618736e0-3c3d-11cf-810c-

00aa00389b71");IAccessible accObj = (IAccessible) AccessibleObjectFromWindow(wHandle,OBJID_WINDOW, ref uid);

Mattias

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


Hi Mattias,

what to say...... you just became my personal hero :)

works perfectly...... and I'd never have thought about
Guid uid = new Guid("618736e0-3c3d-11cf-810c-
00aa00389b71") by myself ....

thx a lot :)

Sven

Nov 15 '05 #4
-----Original Message-----
Sven,
[DllImport("oleacc.dll",CharSet=CharSet.Auto)]
public static extern long AccessibleObjectFromWindow (
long hwnd,
long dwId,
[MarshalAs(UnmanagedType.Struct)]UUID riid,
[MarshalAs(UnmanagedType.Interface)]object ppvObject);
I would declare it as

[DllImport("oleacc.dll", PreserveSig=false)]
[return: MarshalAs(UnmanagedType.Interface)]
public static extern object AccessibleObjectFromWindow (
IntPtr hwnd,
uint dwId,
ref Guid riid);

And call it with

Guid uid = new Guid("618736e0-3c3d-11cf-810c-

00aa00389b71");IAccessible accObj = (IAccessible) AccessibleObjectFromWindow(wHandle,OBJID_WINDOW, ref uid);

Mattias

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


Hi Mattias,

what to say...... you just became my personal hero :)

works perfectly...... and I'd never have thought about
Guid uid = new Guid("618736e0-3c3d-11cf-810c-
00aa00389b71") by myself ....

thx a lot :)

Sven

Nov 15 '05 #5

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

Similar topics

1
by: John Altland | last post by:
Here is my basic problem. I have a form that executes a cpu instensive algorithm occupying the first thread. When the algorithm is executed another form pops up telling the user the progress that...
5
by: RickDee | last post by:
Please help, anybody. I am trying to write a program so that it can launch an exe file ( which is also genereated in C# ) and then simulate the button clicking and invoke the methods inside the...
5
by: Stephen Lamb | last post by:
I have a background worker thread which I start from a form's HandleCreated event that makes calls back to the form using Invoke. During shutdown the form is disposed and the background worker...
2
by: rawCoder | last post by:
Hi I am having this InvalidOperationException with message Cannot call Invoke or InvokeAsync on a control until the window handle has been created This is raised when i try to invoke a method...
0
by: Paul Tomlinson | last post by:
Morning all. Let me describe my problem. Main thread creates child objects and threads and starts them Timer on the main thread (which only gets activated after the child threads have started)...
4
by: Charles Law | last post by:
Hi guys. I have two threads: a main thread and a background thread. Lots of stuff happens in the background thread that means I have to update several (lots) of controls on a form. It is...
0
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode...
7
by: Jeff Stewart | last post by:
I need a thread to run a subroutine which updates my main form's progress bar. I've properly marshaled all UI updates to the main UI thread, and after the main thread starts the worker thread, it...
3
by: m.posseth | last post by:
Hello does someone know how i can invoke a method in the underlying thread without the usage of a window handle ?? This works perfect in a form Me.Invoke(New MethodInvoker(AddressOf...
2
by: =?Utf-8?B?a2VubmV0aG1Abm9zcGFtLm5vc3BhbQ==?= | last post by:
vs2005, c# Trying to understand why one way works but the other doesnt. I have not tried to create a simpler mdi/child/showdialog app for posting purposes (I think even this would not be so small...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.