How to access API function of a Managed C++ application?

R

Renato T. Forti

Hi all,

How to access API function of a Managed C++ application?



Sample:





This doesn't work. :):MessageBox.)

----------------------------------------------------------------------------
------------------------

#pragma once





namespace teste

{

using namespace System;

using namespace System::ComponentModel;

using namespace System::Collections;

using namespace System::Windows::Forms;

using namespace System::Data;

using namespace System::Drawing;



/// <summary>

/// Summary for Form1

///

/// WARNING: If you change the name of this class, you will need to
change the

/// 'Resource File Name' property for the managed resource
compiler tool

/// associated with all .resx files this class depends on.
Otherwise,

/// the designers will not be able to interact properly with
localized

/// resources associated with this form.

/// </summary>

public __gc class Form1 : public System::Windows::Forms::Form

{

public:

Form1(void)

{

InitializeComponent();

}



protected:

void Dispose(Boolean disposing)

{

if (disposing && components)

{

components->Dispose();

}

__super::Dispose(disposing);

}

private: System::Windows::Forms::LinkLabel * CallingAPI;



private:

/// <summary>

/// Required designer variable.

/// </summary>

System::ComponentModel::Container * components;



/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

void InitializeComponent(void)

{

this->CallingAPI = new
System::Windows::Forms::LinkLabel();

this->SuspendLayout();

//

// CallingAPI

//

this->CallingAPI->Location = System::Drawing::point(96,
96);

this->CallingAPI->Name = S"CallingAPI";

this->CallingAPI->TabIndex = 0;

this->CallingAPI->TabStop = true;

this->CallingAPI->Text = S"linkLabel1";

this->CallingAPI->LinkClicked += new
System::Windows::Forms::LinkLabelLinkClickedEventHandler(this,
CallingAPI_LinkClicked);

//

// Form1

//

this->AutoScaleBaseSize = System::Drawing::Size(5, 13);

this->ClientSize = System::Drawing::Size(292, 266);

this->Controls->Add(this->CallingAPI);

this->Name = S"Form1";

this->Text = S"Form1";

this->ResumeLayout(false);



}

private: System::Void CallingAPI_LinkClicked(System::Object * sender,
System::Windows::Forms::LinkLabelLinkClickedEventArgs * e)

{

::MessageBox(NULL, "Call API MessageBox Function",
NULL, NULL); /***********************HERE**********************/

}



};

}



And COM+, How to access ? Any Idea?
 
B

Bart Jacobs

Renato,
How to access API function of a Managed C++ application?

Remember to include the windows.h header file!

In form1.cpp, it reads:

#include "Form1.h"
#include <windows.h>

Change this to:

#include <windows.h>
#include "Form1.h"

Now it should work.
And COM+, How to access ? Any Idea?

COM+ components are known in .NET as serviced components. See

MSDN Library
-> Visual Studio .NET
-> .NET Framework
-> Programming with the .NET Framework
-> Writing Serviced Components

Bart Jacobs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top