Click here to Skip to main content
15,896,278 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
AnswerRe: Calling managed function from unmanaged function [modified] Pin
santoshkaif8-Sep-09 17:52
santoshkaif8-Sep-09 17:52 
GeneralRe: Calling managed function from unmanaged function Pin
N a v a n e e t h9-Sep-09 5:49
N a v a n e e t h9-Sep-09 5:49 
QuestionRe: Calling managed function from unmanaged function [modified] Pin
santoshkaif9-Sep-09 8:18
santoshkaif9-Sep-09 8:18 
AnswerRe: Calling managed function from unmanaged function Pin
N a v a n e e t h9-Sep-09 16:35
N a v a n e e t h9-Sep-09 16:35 
QuestionRe: Calling managed function from unmanaged function Pin
santoshkaif10-Sep-09 0:04
santoshkaif10-Sep-09 0:04 
AnswerRe: Calling managed function from unmanaged function Pin
santoshkaif10-Sep-09 0:16
santoshkaif10-Sep-09 0:16 
AnswerRe: Calling managed function from unmanaged function Pin
N a v a n e e t h10-Sep-09 6:08
N a v a n e e t h10-Sep-09 6:08 
GeneralRe: Calling managed function from unmanaged function [modified] Pin
santoshkaif10-Sep-09 7:21
santoshkaif10-Sep-09 7:21 
Yeah, Common language runtime support is set to "clr" only.
Enclosing code just in case to verify if am doing anything wrong

#pragma once
#include <iostream>
#include <stdio.h>
#include <stdarg.h>
#include <sstream>
#include <iostream>
#include <string>
#pragma managed(push, off)
extern "C"{
#include "library.h"
};
#pragma managed(pop)

namespace GUI_APP {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace std;

	int DisplayMessage(const char* p,...);

	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();

			register_func(DisplayMessage);
		}
		static Form1^ GetInstance()
		{
				if(instance == nullptr)
			instance = gcnew Form1();
				return instance;
		}

		void PrintValue(String^ value)
		{
			Console->AppendText(value);
		}

    private:
        static Form1^ instance = nullptr;
		System::Windows::Forms::RichTextBox^  Console;

	protected:
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	protected: 

	private:
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		void InitializeComponent(void)
		{
			this->Console = (gcnew System::Windows::Forms::RichTextBox());
			this->SuspendLayout();
			// 
			// richTextBox1
			// 
			this->Console->Location = System::Drawing::Point(-2, -2);
			this->Console->Name = L"richTextBox1";
			this->Console->Size = System::Drawing::Size(296, 265);
			this->Console->TabIndex = 0;
			this->Console->Text = L"";
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(292, 262);
			this->Controls->Add(this->Console);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->ResumeLayout(false);

		}
#pragma endregion

		void library_func(void)
		{
			library_operation();
		}

		void WriteToScreen(std::stringstream& value)
		{
		   // Constructing managed string from stringstream
		   std::string str = stream.str();
		   String^ managedString = gcnew String(str.c_str());

		   Form1^ form = Form1::GetInstance();
		   form->PrintValue(managedString);
		}
	};

	int DisplayMessage(const char* p,...) 
	{
		const char *temp; int iValue; double dValue; bool percentageFound = false;
		va_list variable_arguements;
		va_start(variable_arguements, p);
		int DisplayedCharCount = 0;

		// string stream to hold the text to print
		std::stringstream stream;
		
		for (temp = p; *temp; temp++) 
		{
			DisplayedCharCount++;
			if(*temp != '%' && !percentageFound)
				stream << *temp;
			else if(!percentageFound)
			{
				percentageFound = true;
				continue;
			}

			if(percentageFound)
			{
				switch (*temp) 
				{
				case 'd':
					iValue = va_arg(variable_arguements, int);
					stream << iValue;
					break;
				default:
					// your code
					break;
				}
				percentageFound = false;
			}
		}
		va_end(variable_arguements);
		WriteToScreen(stream);

		return DisplayedCharCount;
	}
}


following are the error messages

error C2065: 'stream' : undeclared identifier
error C2228: left of '.str' must have class/struct/union
        type is ''unknown-type''
error C3861: 'WriteToScreen': identifier not found
warning C4793: 'vararg' : causes native code generation for function 'int GUI_APP::DisplayMessage(const char *,...)'
        see declaration of 'GUI_APP::DisplayMessage'


pls let me know where i am going wrong?

if i make "DisplayMessage" as member function of "Form1" class, then below error is thrown
'GUI_APP::Form1::DisplayMessage' : a member-function of a managed type cannot be declared with '...'

modified on Thursday, September 10, 2009 1:57 PM

GeneralRe: Calling managed function from unmanaged function Pin
N a v a n e e t h10-Sep-09 16:10
N a v a n e e t h10-Sep-09 16:10 
GeneralRe: Calling managed function from unmanaged function Pin
santoshkaif10-Sep-09 18:43
santoshkaif10-Sep-09 18:43 
QuestionRe: Calling managed function from unmanaged function Pin
santoshkaif21-Sep-09 2:20
santoshkaif21-Sep-09 2:20 
AnswerRe: Calling managed function from unmanaged function Pin
N a v a n e e t h22-Sep-09 15:31
N a v a n e e t h22-Sep-09 15:31 
QuestionMultiple Forms in VS2005 Pin
rtshield6-Sep-09 15:17
rtshield6-Sep-09 15:17 
AnswerRe: Multiple Forms in VS2005 Pin
N a v a n e e t h6-Sep-09 15:58
N a v a n e e t h6-Sep-09 15:58 
QuestionWeird problem with writing to a label in a form. (VC++ 2008) Pin
alzaeem4-Sep-09 6:55
alzaeem4-Sep-09 6:55 
AnswerRe: Weird problem with writing to a label in a form. (VC++ 2008) Pin
N a v a n e e t h4-Sep-09 18:12
N a v a n e e t h4-Sep-09 18:12 
GeneralRe: Weird problem with writing to a label in a form. (VC++ 2008) Pin
alzaeem5-Sep-09 17:32
alzaeem5-Sep-09 17:32 
AnswerRe: Weird problem with writing to a label in a form. (VC++ 2008) Pin
Luc Pattyn6-Sep-09 1:20
sitebuilderLuc Pattyn6-Sep-09 1:20 
Questionmodify a DLL(binary) to call another DLL function/exe or embed a code...I need some concepts clarification Pin
Member 43963092-Sep-09 21:58
Member 43963092-Sep-09 21:58 
AnswerRe: modify a DLL(binary) to call another DLL function/exe or embed a code...I need some concepts clarification Pin
Richard MacCutchan3-Sep-09 2:24
mveRichard MacCutchan3-Sep-09 2:24 
Questionthe error in managed c++ function call unmanaged c++ function Pin
jetjeankimo2-Sep-09 17:43
jetjeankimo2-Sep-09 17:43 
AnswerRe: the error in managed c++ function call unmanaged c++ function Pin
N a v a n e e t h3-Sep-09 0:00
N a v a n e e t h3-Sep-09 0:00 
GeneralRe: the error in managed c++ function call unmanaged c++ function Pin
jetjeankimo3-Sep-09 16:12
jetjeankimo3-Sep-09 16:12 
GeneralRe: the error in managed c++ function call unmanaged c++ function Pin
N a v a n e e t h4-Sep-09 5:59
N a v a n e e t h4-Sep-09 5:59 
GeneralRe: the error in managed c++ function call unmanaged c++ function Pin
jetjeankimo4-Sep-09 16:31
jetjeankimo4-Sep-09 16:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.