how to call windows.h functions within a header file (basically i created an app using windows form application...and i need to call windows.h function when hitting certain buttons)
I'm not sure what your question involves -- if you #include <windows.h> in your application, then you can call Windows functions anywhere in your program.
#include "stdafx.h"
#pragma once
namespace WindowsFormsApplication1 {
usingnamespace System;
usingnamespace System::ComponentModel;
usingnamespace System::Collections;
usingnamespace System::Windows::Forms;
usingnamespace System::Data;
usingnamespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->SuspendLayout();
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
};
}
ok i want to do:
1 2 3 4 5 6 7
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
/*i want to call RegOpenKeyValue() for example
i cant do it directly it wont work*/
}
};
}
#include <windows.h>
#include "stdafx.h"
//(the rest of your program code goes here)
Also, make sure that Advapi32.lib is added in your Project Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies. This .lib is required for using RegOpenmKeyEx().
EDIT:
If you look at the bottom of the webpage linked by modoran, you'll see that the MSDN documentation for RegOpenmKeyEx() mentions:
Requirements:
Minimum supported client:
Windows 2000 Professional [desktop apps only]
Minimum supported server:
Windows 2000 Server [desktop apps only]
Header:
Winreg.h (include Windows.h)
Library:
Advapi32.lib
DLL:
Advapi32.dll
Unicode and ANSI names:
RegOpenKeyExW (Unicode) and RegOpenKeyExA (ANSI)
That's how you can determine the requirements for a function to work -- this one needs Advapi32.lib to work (and of course including windows.h).
yes i considered that .... even if you changed this function to any other function it wont work...i tried GetModuleHandle() and FindWindow() ....the same error pops out....try it you will see....my purpose is to know why the previous function(or Windows.h functions) cannot be invoked??
my purpose is to know why the previous function(or Windows.h functions) cannot be invoked??
You are mixing Managed (.net framework) code with unmanaged (native) code.
I would suggest that, you don't know the difference, you spend a little time looking at the two 'ways' of programming windows and make sure you are on the right track for what you want to learn.
Grey Wolf has a good suggestion, you have to decide which path you're going down. if you choose managed: this will help
This is your namespace directive. I put it last.
thanks a lot you all....i didnt know those are totally different ....the last question
Ok what is this operator suppose to mean ^...as i know it is supposed to be used in bitwise operation .....in this
1 2
RegistryKey^
RegistryKey //what is the difference??