|
myapp1::Form1::ioBOX.Appendtext("x");
Gives this error:
error C2228: left of '.Appendtext' must have class/struct/union type
type is ''
----------------------------------------------------------------------
Any ideas?
----------------------------------------------------------------------
#pragma once
extern "C" int magiccalc(void);
namespace myapp1
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
magiccalc();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::TextBox * ioBOX;
private:
void InitializeComponent(void)
{
this->ioBOX = new System::Windows::Forms::TextBox();
... ...yadda yadda
}
public:
static void TOioBox(int outnum)
{
ERROR----> myapp1::Form1::ioBOX.Appendtext("x");
}
};
}
extern "C"
{
void showme(int wrapnum) // My wrapper for C
{
myapp1::Form1::TOioBox(3);
}
}
|
|
|
|
|
Name mangling is a technique used by the compiler.
Each compiler can have different algorithm for name mangling.
I don't think its possible to prevent name mangling.
Rahul
|
|
|
|
|
Hi all!
I'm want to use my library in another project. I have compiled my lib (tmf.lib) succesfully. But when i I whant to use there a Linking error:
error LNK2001: unresolved external symbol "void __cdecl tmf_close(struct TmfClass *)" (?tmf_close@@YAXPAUTmfClass@@@Z)
error LNK2001: unresolved external symbol "struct TmfClass * __cdecl tmf_init(char const *)" (?tmf_init@@YAPAUTmfClass@@PBD@Z)
The problem is that I've added tmf.lib to project settings library modules and copied tmf.lib and some header files to project dir.
Does anyone know how to solve this problem?
PS I also tryed to this similar stuff but with a very small lib containg only a few functions a every thing was ok.
Pain is a weakness living the body
|
|
|
|
|
Add the project dir to the list of directories searched for libraries/headers in the IDE (Tools | Options -- find the VC++ settings)
|
|
|
|
|
hmm! not working any other ideas. I think its something with precompiled headers. .
Pain is a weakness living the body
|
|
|
|
|
And its not working after I added all header and source files to project. All the time the same error!!!
Pain is a weakness living the body
|
|
|
|
|
Its working. The problem was with compiler params lib was compiled as ansi C and my projekt is in VC++ . After compiling lib in c++ compiler everything is OK
Pain is a weakness living the body
|
|
|
|
|
My ERROR:
sim50avc error LNK2001: unresolved external symbol "void __cdecl showme(int)" (?showme@@$$J0YAXH@Z)
I have created a simple Form project and tried to mix C++ and my existing C code. With problems of course. Here is the important code.
/* BEGIN - don.c */
/* ############################################################ */
/* ### This just a cut-down example of my C code ### */
/* ############################################################ */
/* ### The fact that it is C code and not C++ cannot change ### */
/* ############################################################ */
#include
extern void showme(int); /* call this routine in Form1.h */
int magiccalc() /* Magic calculation - written in C */
{
showme(3); /* use the integer 3 instead of showing the calculations code */
return(0);
}
/* ############################################################ */
/* END - don.c */
/* BEGIN - Form1.h */
#pragma once
extern "C" int magiccalc(void);
namespace sim50avc
{
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 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.
///
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
int num;
InitializeComponent();
num = magiccalc(); /* Call magiccalc in don.c */
/* num is a meaningless return value */
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::TextBox * inputBox;
private: System::Windows::Forms::TextBox * outputBox;
private:
///
/// Required designer variable.
///
System::ComponentModel::Container * components;
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
void InitializeComponent(void)
{
this->inputBox = new System::Windows::Forms::TextBox();
this->outputBox = new System::Windows::Forms::TextBox();
this->SuspendLayout();
//
// inputBox
//
this->inputBox->Location = System::Drawing::Point(16, 24);
this->inputBox->Multiline = true;
this->inputBox->Name = S"inputBox";
this->inputBox->Size = System::Drawing::Size(256, 88);
this->inputBox->TabIndex = 1;
this->inputBox->Text = S"inputBox";
//
// outputBox
//
this->outputBox->Location = System::Drawing::Point(16, 184);
this->outputBox->Multiline = true;
this->outputBox->Name = S"outputBox";
this->outputBox->Size = System::Drawing::Size(256, 88);
this->outputBox->TabIndex = 2;
this->outputBox->Text = S"";
//
// Form1
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(292, 302);
this->Controls->Add(this->outputBox);
this->Controls->Add(this->inputBox);
this->Name = S"Form1";
this->Text = S"Form1";
this->ResumeLayout(false);
}
public:
void __cdecl showme(int thenum)
{
MessageBox::Show(S"abc", S"Result...");
}
};
}
/* END - Form1.h */
Thank You in advance
Don
P.S. - I can send the project in zipped form if anyone wants to take a look.
|
|
|
|
|
Refer to Interoperating with Unmanaged Code in the MSDN for more information.
For one, you're mixing Managed C++ with C. If you want to use .NET objects from C, you must expose the .NET objects as COM objects first. You can then call into COM objects using the standard COM API using C++. It is possible to use C, but it's more headache than it's worth.
What is it you're trying to do here?
If you're just trying to show the result from magiccalc , just return the value from the C code without displaying anything:
int magiccalc()
{
return someResult;
}
extern __cdecl int magiccalc();
public:
Form1()
{
InitializeComponent();
int num = magiccalc();
}
Of course, if the magiccalc or other routine(s) are in an external DLL, use them via Consuming Unmanaged DLL Functions.
|
|
|
|
|
In a nutshell, I want to display data computed by my current code on a windowed form. My computations are produced by routines in maybe 50 or so "C compatible" source modules.
|
|
|
|
|
Then just call into and retrieve the computation results from the C modules from C++.NET, and display the results in C++.NET as stated above. No need to "retrofit" the C. Just make sure the C prototypes are visible to the C++ portions and away you go.
|
|
|
|
|
That should be the case but I am getting a link-time error from the C object module that SHOWME (called from C but coded as function in cpp) is an unresolved external.
public:
void __cdecl showme(int thenum)
{
MessageBox::Show(S"abc", S"Result...");
}
Should I have declared the function differently so that C can see it?
I appreciate any help you can give.
Don
|
|
|
|
|
First, that showme should be in your C++ and doesn't need the __cdecl . Second, you have to declare the prototype for the C function you'll be calling to get that int result from.
|
|
|
|
|
I've gotten past this problem.
Thanks to all
Don
|
|
|
|
|
Hi all,
I have created a DLL from some C++ code (to call from my C# app).
The DLL creates and writes to a couple of files.
However, it writes them to the folder last used by the C# app.
1. Why? (Less important)
2. How do I specify where to write the file, relative to the DLL file. (More Important)
Thanks in advance for any suggestions/hints.
J
---
|
|
|
|
|
It'll write to a relative path to the EntryAssembly's Working Folder. To find out what that is, use Environment.CurrentDirectory Property. If you want the path relative to the DLL itself (excuse the C# throughout, it was faster to type -- the C++ is very similar):
string baseDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
If you have a bare file name/relative path, relativeFileName , you can construct a full path to the file with the above baseDirectory thus:
string filePath = Path.Combine(baseDirectory, relativeFileName);
|
|
|
|
|
Thanks Ian,
I'm just setting the directory using
Environment.CurrentDirectory and string filePath = Path.Combine(baseDirectory, relativeFileName);
before I run the DLL - saves me from editing the DLL, and is easier to keep track of.
Thanks again, J
---
|
|
|
|
|
I need to implement a timer, so I copied the example from the help screen, and pasted it into a new .net console application. When I try to build it I get the following error message:
.....\mytimer.cpp(22): error C2061: syntax error : identifier 'ElapsedEventArgs'
What am I missing???
// This is the main project file for VC++ application project
// generated using an Application Wizard.
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
// the following is from sdk help
__gc class Timer1
{
public:
static void Main() {
System::Timers::Timer* aTimer = new System::Timers::Timer;
aTimer->Elapsed += new ElapsedEventHandler(0, Timer1::OnTimedEvent);
// Set the Interval to 5 seconds.
aTimer->Interval=5000;
aTimer->Enabled=true;
}
private:
// Specify what you want to happen when the Elapsed event is raised.
static void OnTimedEvent(Object* source, ElapsedEventArgs* e)
{
Console::WriteLine(S"Hello World!");
// aTimer->Enabled=true;
}
};
int _tmain()
{
Timer1::Main();
Console::WriteLine(S"Press \'q\' to quit the sample.");
while(Console::Read()!='q');
return 0;
}
|
|
|
|
|
on the line with #using..., the code has #using mscorlib.dll, but somehow didn't paste correct...
|
|
|
|
|
Hello guys,
I'm a newbee in .NET programming. Haven spent the last 4 months working with C#.NET. I want to have a feel of Managed C++ like the big boys do. Links to "very good" free e-books will be highly appreciated.
Thanks 4 always being there sirs.
...the mind is not a vessel to be filled but a fire to ignited
|
|
|
|
|
try to use eMule and search for Thinking in C++. There are few pdfs available. Autor was invertor of C++.
Pain is a weakness living the body
|
|
|
|
|
How to write the blinking word in colour?
for e.g Invalid Password in yellow bold + blinking.
thanks
|
|
|
|
|
Setup a timer and enable it if the password is invalid -- and when it's Tick event fires, change the foreground color appropriately
|
|
|
|
|
how to write code like that? i have no idea what to write...
|
|
|
|
|
Check out the System.Windows.Forms.Timer class.
Basically, you'd set up a handler for the Tick event to do the foreground color switching for you.
Set a decent Interval, like 1000 for one second, on the Timer.
When you need to blink, call Start. When you're done blinking, call Stop.
|
|
|
|