P/Invoke problem

S

Sven Gnagi

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
 
M

Mattias Sjögren

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
 
G

Guest

-----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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top