Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2007

Tip: Looking for answers? Try searching our database.

calling win32 api from C++ forms project

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve Richter - 05 Mar 2007 03:41 GMT
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
Carl Daniel [VC++ MVP] - 05 Mar 2007 04:46 GMT
> 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
[quoted text clipped - 13 lines]
> 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
Steve Richter - 05 Mar 2007 05:59 GMT
On Mar 4, 11:46 pm, "Carl Daniel [VC++ MVP]"
<cpdaniel_remove_this_and_nos...@mvps.org.nospam> 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
[quoted text clipped - 15 lines]
>
> Same as always:  <windows.h>

thanks.  I know it was a simple question, but it it actually helped a
lot.

-Steve

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.