473,396 Members | 1,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,396 software developers and data experts.

calling winAPI functions in vb.net

3
have to "translate" / up-date a program that was written in C about 20 years ago to VB.net due to its old SQL connection style that isn't compatible anymore. However, I have minimal experience with C and even less with the winAPI(which the C application uses)... I was wondering, can the same functions from the API be use in VB.net?

I have been able to add a declaration like this:

Expand|Select|Wrap|Line Numbers
  1.   <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
  2.         Public Shared Function SetWindowText(hWnd As IntPtr, lpString As String) As Boolean
  3.         End Function 
to get a window Handle as IntPtr ( in vb.net). However the C program uses functions such as:

Expand|Select|Wrap|Line Numbers
  1.   BOOL NEAR GoModal( HINSTANCE hInstance, LPCSTR lpszTemplate,HWND hWnd, DLGPROC lpDlgProc, LPARAM lParam )
By importing the user32.dll I can't get the hWnd handle but I can get the IntPtr ( If I understood well, is a point to a window as an integer right? Kinda similar to hWnd --> I could be TOTALLY wrong, but this is what I understood)

As I go to the definition of each type (i.e: NEAR , HINSTANCE, LPCSTR, etc...) I try to find an equivalent call in VB but ... its useless. For instance, I've seen a lot of questions on google asking on how to get the HINSTANCE such as:

Expand|Select|Wrap|Line Numbers
  1. System.Runtime.InteropServices.Marshal.GetHINSTANCE _(System.Reflection.Assembly.GetExecutingAssembly.GetModules() _(0)).ToInt32() 
which does work in Visual Studio (no errors) BUT I need to create an object like this :

Expand|Select|Wrap|Line Numbers
  1.  Dim hinst as HINSTANCE 
which is how the C code made it ( of course not with dim! haha)

Ultimately, my question is, would such call exist in vb.net / even be useful with the more modern framework and such?
Jun 3 '16 #1
1 2036
iam_clint
1,208 Expert 1GB
http://www.pinvoke.net/default.aspx/....setwindowtext
Expand|Select|Wrap|Line Numbers
  1. SetWindowText(Process.GetCurrentProcess().MainWindowHandle, "Amazing!")
  2.  
Jun 6 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John Harrison | last post by:
What are the rule concerning calling member functions from an initialiser list? Suppose I have class C : public B { public: C() : x(), y(f()), z() {} private: Y f(); X x;
5
by: Praveen Srinivasan | last post by:
Hi all, Are there any important issues that one should be aware of when calling C++ functions from C? In particular, I'm passing a function pointer to a C routine in a library, and in that...
10
by: reynoldscraigr | last post by:
Hi All, I am trying to call 2 functions from the 1 onMouseOver event on an anchor tag, but I can't seem to get it to work. the following should demonstrate <a...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
6
by: Michael Maercker | last post by:
hi! i knew how to define api-calls in vb6... how do i do it in c#? say, for example, "SetWindowPos"...? thx, mike
1
by: Gerald Klix | last post by:
I read the whol email thread carefully and could not find any sentence by Guido, which states that he does not accept ctypes for the standard library. He just declined to rewrite winreg. Did I miss...
46
by: Usenet User | last post by:
I need to be able to call the same API function from VB, which will reside in different DLLs. While all of the functions have the same signature and name, DLL file names are not known at compile...
4
by: Meya-awe | last post by:
Hi, What does C# has to offer for calling system functions from within the VS .NET C# project? I want to kickoff a script or a batch file from my code. thanks, BRAMOIN *** Sent via...
47
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both...
6
by: teju | last post by:
hi, i have a code written in c now merged with c++ code i mean i am calling c functions in c++ using extern "C" but now i want to use some objects declared and defined in c++ to be available in...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.