473,406 Members | 2,378 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,406 software developers and data experts.

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
tapeToolStripMenuItem_Click( System::Object^ sender,
System::EventArgs^ e)
{

HANDLE hTape = CreateFile( "\\\\.\\TAPE0", 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 3079
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
tapeToolStripMenuItem_Click( System::Object^ sender,
System::EventArgs^ e)
{

HANDLE hTape = CreateFile( "\\\\.\\TAPE0", 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,off)
#include "mynativeheader.h"
#pragma managed(pop)

-cd
Mar 5 '07 #2
On Mar 4, 11:46 pm, "Carl Daniel [VC++ MVP]"
<cpdaniel_remove_this_and_nos...@mvps.org.nospamwr ote:
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
tapeToolStripMenuItem_Click( System::Object^ sender,
System::EventArgs^ e)
{
HANDLE hTape = CreateFile( "\\\\.\\TAPE0", 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
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"...
11
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
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...
8
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...
6
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,...
0
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...
3
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?...
14
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...
10
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
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.