473,756 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling win32 api from C++ forms project

using vs2005, the wizard created a c++ forms project for me. Now in
the form1.h file I have a menu item click handler that I would like to
add some win32 api code to:

private: System::Void
tapeToolStripMe nuItem_Click( System::Object^ sender,
System::EventAr gs^ e)
{

HANDLE hTape = CreateFile( "\\\\.\\TAP E0", GENERIC_READ |
GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL);

}

What header file do I use for the HANDLE and DWORD macros? Where do I
place the #include stmts in the form1.h file?

I need to use other win32 APIs like SetTapePosition and I got the
function declaration to be accepted in the main project .cpp file.
But linkage failed because of "unresolved externals
SetTapePosition ". How do I add kernel32 to my project?

( I actually used to code Visual C++ for a number of years. The
executable code in the form1.h file is what is confusing me the
most. )

thanks,

-Steve

Mar 5 '07 #1
2 3098
Steve Richter wrote:
using vs2005, the wizard created a c++ forms project for me. Now in
the form1.h file I have a menu item click handler that I would like to
add some win32 api code to:

private: System::Void
tapeToolStripMe nuItem_Click( System::Object^ sender,
System::EventAr gs^ e)
{

HANDLE hTape = CreateFile( "\\\\.\\TAP E0", GENERIC_READ |
GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL);

}

What header file do I use for the HANDLE and DWORD macros? Where do I
place the #include stmts in the form1.h file?
Same as always: <windows.h>
I need to use other win32 APIs like SetTapePosition and I got the
function declaration to be accepted in the main project .cpp file.
But linkage failed because of "unresolved externals
SetTapePosition ". How do I add kernel32 to my project?
Just add it to the list of libraries on the linker input settings page.
>
( I actually used to code Visual C++ for a number of years. The
executable code in the form1.h file is what is confusing me the
most. )
IMO, it's best to keep your managed and unmanaged code in separate files,
using self contained header files as the linkage between them (i.e. header
files that don't depend on windows.h or the C++ standard library - the fewer
dependencies that need to cross the managed/unmanaged boundary - both at
runtime and at compile time - the better).

Surround the #include of your native header files with pragmas to control
the managed/unmanaged settings:

#pragma managed(push,of f)
#include "mynativeheader .h"
#pragma managed(pop)

-cd
Mar 5 '07 #2
On Mar 4, 11:46 pm, "Carl Daniel [VC++ MVP]"
<cpdaniel_remov e_this_and_nos. ..@mvps.org.nos pamwrote:
Steve Richter wrote:
using vs2005, the wizard created a c++ forms project for me. Now in
the form1.h file I have a menu item click handler that I would like to
add some win32 api code to:
private: System::Void
tapeToolStripMe nuItem_Click( System::Object^ sender,
System::EventAr gs^ e)
{
HANDLE hTape = CreateFile( "\\\\.\\TAP E0", GENERIC_READ |
GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL);
}
What header file do I use for the HANDLE and DWORD macros? Where do I
place the #include stmts in the form1.h file?

Same as always: <windows.h>
thanks. I know it was a simple question, but it it actually helped a
lot.

-Steve

Mar 5 '07 #3

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

Similar topics

1
2351
by: Luca Arena | last post by:
Hi, I would like to know if it is possible to call the php parser from a Win32 program (e.g. a VB or C++ program), WITHOUT calling the commandline php.exe utility. I mean, is there any "php_parse" function, exported by the php5ts.dll, which I can declare in my Win program and then call to parse a php script? Thanks in advance Luca
11
1972
by: j23 | last post by:
I have library (static) testlib.cpp: #include <stdarg.h> void xxx(...) { char buf; va_list args; va_start(args, buf); va_end(args); }
3
2717
by: Gustavo L. Fabro | last post by:
Greetings! I'm a newbie in Visual C++ .NET (have programmed in Borland C++ and Builder for long) and I am trying to do a very simple thing, but I'm stuck. I created an (unmanaged) DLL project with a sample function, and tried to call it from a ".NET Forms" project. All I get are "Unresolved External" errors from the Linker!
8
4772
by: Tony Johansson | last post by:
Hello! I just wonder what the difference is between a native win32-app and MFC. What I know is that you can use Win32 API in both cases. I think an MFC application is connected with a GUI which a win32 is not. You may correct me if I'm wrong on this point. //Tony
6
1709
by: Amjad | last post by:
Hi, I want to make a project that calls and executes a function (VB code) made in a seperate file in the Application Folder. I know I can create the function in my project and call it internally, but I want to put the function's code in an external file, so that future updates to the function will require a replacing the function file instead of re-installing the whole project. Can you give me ideas on how I can make small updates to my...
0
1179
by: Scott Gunn | last post by:
Hello I'm trying to scroll a region of graphics, the best way I can see is to use the ScrollWindowEx API because it is designed for doing this However it doesn't work correctly, Why? Here is my code: Public Class Win32
3
1656
by: fatemah.aldouli | last post by:
Hi, I am new to C# (and not an expert in C++). I am trying to use a C++ program to call a C# windows application (to be specific the Main() method of the C# application). What should I do? Somebody else created the C# app...and I am just trying to use it. I am thinking about adding a C++ win32 project to the solution (where the C# app exists) and somehow link the C# application, which is not a DLL, to the C++ one. I just do not know how!...
14
8162
by: krishna1412 | last post by:
Currently i am working in a project of report generation in MS ACCESS. The tables are in sql server 2000. I have to write stored proc in ms access. Illustration: I am having a stored proc as follows name: myproc -------------------
10
6999
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lparam) {
0
9271
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
10031
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
9838
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
9708
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8709
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...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5140
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...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.