?
Solved

Get Window Handle, Working With API

Posted on 2010-04-02
7
Medium Priority
?
478 Views
Last Modified: 2012-05-09
I'm new to working with an API, and I need to send it a handle to my calling application main window.

In my VB project, I'm trying to make a link to a C++ API via my Form, Form4. At current, I've placed a call to the function to make a link to the API in the Button.Click() sub for each button I click on that does something. I'm currently passing it a handle like this each time:

Me.Handle.ToInt32

What I'd like to do is establish the connection once by clicking on a certain button, and have the connection still work each time I click any other button on my form. At current, I've only been able to make it work by re-establishing the connection in each Button.Click() sub for each button I want to click on that will do different things with the API. I'm wondering how I would go about doing this once. Am I not passing the right handle to my form?
0
Comment
Question by:diablo089
  • 4
  • 2
7 Comments
 
LVL 12

Expert Comment

by:lazyberezovsky
ID: 29459764
Use
[DllImport("USER32.DLL")]
private static extern IntPtr SetParent(IntPtr child, IntPtr parent);
0
 

Author Comment

by:diablo089
ID: 29473626
Hmm... is this the right thing to do if I just work from a single form? I don't bring up any other forms when I click the buttons to perform actions.
0
 

Author Comment

by:diablo089
ID: 29475027
What I'm doing is connecting to a database via an external API. If I establish the connection in the Button.Click() sub of each button on my form, it works fine. If I only put the API call to establish the connection in one button.click() sub, when I go to click any other button on my form, the connection is apparently dead, because my API calls don't work.

I just started using API calls recently, so I might not have the right methodology about this, or I might be doing something wrong.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 29475234
Show us the code you are using.
0
 

Author Comment

by:diablo089
ID: 29476205
Prototypes of functions:

Declare Function API_Init Lib "API2.dll" (ByVal Handle As Integer, ByVal Path As String) As Integer
Declare Function API_Open Lib "API2.dll" (ByVal Path As String) As Integer

I use it in a Button.Click() sub like this:

Dim rInit As Integer
Dim rOpen As Integer
rInit = API_Init(Me.Handle, vbNullString)
rOpen = API_Open(Path)

So, if I put this code in each of my button.click subs for my various buttons, it works just fine. What I'd like to know is if I can put this in a single button.click sub, establishing the connection, and have the API connection still connected for any other button click.

At current, if I put it in a single button.click sub, my connection is dead in any other button.click sub that I don't put the connection code in. First I thought it might be some kind of scope issue, but I dunno.
0
 

Author Comment

by:diablo089
ID: 29605635
Any ideas?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 29699525
Dont know what this API is so I think you need to reinitialize the API as this may be the limitation of the API.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses
Course of the Month4 days, 16 hours left to enroll

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question