473,799 Members | 3,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

P/Invoke problem

Hi folks,

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

I try to use :

[DllImport("olea cc.dll",CharSet =CharSet.Auto)]
public static extern long AccessibleObjec tFromWindow (
long hwnd,
long dwId,
[MarshalAs(Unman agedType.Struct )]UUID riid,
[MarshalAs(Unman agedType.Interf ace)]object ppvObject);

public struct UUID
{
public long Data1;
public int Data2;
public int Data3;
[MarshalAs(Unman agedType.ByValA rray,SizeConst= 8)]
public byte[] Data4;
}
public static void TestAA()
{
UUID uid;
uid.Data1 = (long)0x618736e 0;
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 = AccessibleObjec tFromWindow
(wHandle,OBJID_ WINDOW,uid,accO bj);

but always get a E_INVALIDARG return value.

I also tried

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

thx :)

Sven

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

Willy.

"Sven Gnagi" <Sv*******@hotm ail.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("olea cc.dll",CharSet =CharSet.Auto)]
public static extern long AccessibleObjec tFromWindow (
long hwnd,
long dwId,
[MarshalAs(Unman agedType.Struct )]UUID riid,
[MarshalAs(Unman agedType.Interf ace)]object ppvObject);

public struct UUID
{
public long Data1;
public int Data2;
public int Data3;
[MarshalAs(Unman agedType.ByValA rray,SizeConst= 8)]
public byte[] Data4;
}
public static void TestAA()
{
UUID uid;
uid.Data1 = (long)0x618736e 0;
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 = AccessibleObjec tFromWindow
(wHandle,OBJID_ WINDOW,uid,accO bj);

but always get a E_INVALIDARG return value.

I also tried

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

thx :)

Sven

Nov 15 '05 #2
Sven,
[DllImport("olea cc.dll",CharSet =CharSet.Auto)]
public static extern long AccessibleObjec tFromWindow (
long hwnd,
long dwId,
[MarshalAs(Unman agedType.Struct )]UUID riid,
[MarshalAs(Unman agedType.Interf ace)]object ppvObject);


I would declare it as

[DllImport("olea cc.dll", PreserveSig=fal se)]
[return: MarshalAs(Unman agedType.Interf ace)]
public static extern object AccessibleObjec tFromWindow (
IntPtr hwnd,
uint dwId,
ref Guid riid);

And call it with

Guid uid = new Guid("618736e0-3c3d-11cf-810c-00aa00389b71");
IAccessible accObj = (IAccessible)Ac cessibleObjectF romWindow(wHand le,
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("olea cc.dll",CharSet =CharSet.Auto)]
public static extern long AccessibleObjec tFromWindow (
long hwnd,
long dwId,
[MarshalAs(Unman agedType.Struct )]UUID riid,
[MarshalAs(Unman agedType.Interf ace)]object ppvObject);
I would declare it as

[DllImport("olea cc.dll", PreserveSig=fal se)]
[return: MarshalAs(Unman agedType.Interf ace)]
public static extern object AccessibleObjec tFromWindow (
IntPtr hwnd,
uint dwId,
ref Guid riid);

And call it with

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

00aa00389b71");IAccessible accObj = (IAccessible) AccessibleObjec tFromWindow(wHa ndle,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("olea cc.dll",CharSet =CharSet.Auto)]
public static extern long AccessibleObjec tFromWindow (
long hwnd,
long dwId,
[MarshalAs(Unman agedType.Struct )]UUID riid,
[MarshalAs(Unman agedType.Interf ace)]object ppvObject);
I would declare it as

[DllImport("olea cc.dll", PreserveSig=fal se)]
[return: MarshalAs(Unman agedType.Interf ace)]
public static extern object AccessibleObjec tFromWindow (
IntPtr hwnd,
uint dwId,
ref Guid riid);

And call it with

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

00aa00389b71");IAccessible accObj = (IAccessible) AccessibleObjec tFromWindow(wHa ndle,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
4107
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 has been made. Whenever I attempt to update my frmProgress, the events are put placed at the end of the thread's queue and executed after my algorithm is finished. Using the frmProgress.Label.Invoke method with delagates, I have heard would fix...
5
4313
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 exe. The button clicking part is working fine, but I just cannot get the method call. Here is my program snippet. **************************************************************
5
8114
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 thread is aborted by the system. How is one to keep the background thread from calling form.Invoke after the form's window handle has been destroyed? This is definitely happening in my application. I haven't read anything about this problem in...
2
3009
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 with arguments I need to do this as the method is being called Asynchronously from elsewhere using delegate's BeginInvoke method. The form is well created/initialized yet the messages states otherwise.
0
1473
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) periodically calls a function Refresh(). This refresh function runs on its own thread and queries our database for new jobs. For each job found this timer invokes a delegate on one of the child thread objects. I then get the error "Cannot call...
4
3584
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 quite tiresome to have to write code to call MyControl.Invoke for each control on the form, along with the delegates that are required for each. Is there a better way to do this? What I mean is, if I could marshal the
0
2961
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 thread. so far so good. all contacts r added properly. now when another login adds me in his contact, i recv a subscription, so i popup a form and ask for accept/reject. this all happens in a separate thread. popup form gets opened and choice is...
7
2132
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 waits for the worker thread to complete by means of a while t.isAlive, sleep(0) mechanism. But when my worker thread calls my UpdateProgressBar routine, which calls Me.Invoke, the invoke call blocks forever. But I can't figure out why the main...
3
2244
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 ShowRecvdMessage))
2
4427
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 or simple). I am hoping the description will generate some ideas I can check out. PROBLEM: ----------------- Switching to UI thread using Invoke(), everything seems good.
0
9688
marktang
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...
0
9546
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,...
0
10490
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9078
agi2029
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...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
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...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.