|
|
Yeah I tried that, several hundred compiler errors. Even if I did get it to compile, wouldn't that be compiled to managed code? I don't need this particular piece of code in managed land...
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Lent Revisited
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I've got a C++/CLI library I'm using to wrap some native C methods in order to call them easily from another .NET language.
This is probably an easy question, but how can I convert a .NET string (System::String) to a LPCSTR? I'm new the the CLI extensions for C++, and google doesn't give me anything other than the old MSDN article which refers to solutions using the old MC++ syntax.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Lent Revisited
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Judah Himango wrote: I've got a C++/CLI library I'm using to wrap some native C methods in order to call them easily from another .NET language.
This is probably an easy question, but how can I convert a .NET string (System::String) to a LPCSTR? I'm new the the CLI extensions for C++, and google doesn't give me anything other than the old MSDN article which refers to solutions using the old MC++ syntax.
Hello Judah,
See http://www.codeproject.com/managedcpp/StringConvertor.asp[^]
If you don't want to use the class, look at the source code to see how it's done.
Regards,
Nish
|
|
|
|
|
|
Hi..I need a sample code or a dll that detect if any hardware connected to parallel port and usb.
karanba
|
|
|
|
|
One solution to serial port communication is CreateFile() if you are running on Win32 console.
Kuphryn
|
|
|
|
|
I need to know how I can read the content of a pdf document using c++.
Allang Garder
|
|
|
|
|
Allang Garder wrote: using c++.
do you know this is the Managed C++ forum (for .NET framework so) ?
|
|
|
|
|
How would you do it in cli? I would
be interested.
|
|
|
|
|
hi, i am having some trouble with this basic example code, i can't figure out why i am getting an error, null reference!
please help
thanks
#include "stdafx.h"<br />
<br />
#using mscorlib.dll<br />
using namespace std; <br />
<br />
<br />
class Foo<br />
{<br />
public:<br />
Foo();<br />
~Foo();<br />
void DoSomeFoo();<br />
};<br />
<br />
Foo::Foo() <br />
{<br />
cout<<"Constructor called!"<<endl;<br />
}<br />
Foo::~Foo() <br />
{<br />
cout<<"Destructor called"<<endl;<br />
}<br />
<br />
void Foo::DoSomeFoo()<br />
<br />
{<br />
cout<<"Do something funny!"<<endl;<br />
cout<<"Burrrp!"<<endl;<br />
}<br />
<br />
__gc class MFoo<br />
{ <br />
private:<br />
Foo * _foo;<br />
public:<br />
MFoo();<br />
~MFoo();<br />
void ManagedDoSomeFoo();<br />
};<br />
<br />
MFoo::MFoo() <br />
{<br />
_foo = new Foo();<br />
}<br />
MFoo::~MFoo()<br />
{<br />
delete _foo;<br />
}<br />
<br />
void MFoo::ManagedDoSomeFoo() <br />
{<br />
_foo->DoSomeFoo();<br />
}<br />
<br />
<br />
int _tmain() <br />
{ <br />
<br />
<br />
MFoo*myfoo;<br />
myfoo->ManagedDoSomeFoo();<br />
<br />
return 0; <br />
}
|
|
|
|
|
where in the code are you getting this error, and what does the error message say ?
does it happen at runtime or before ?
|
|
|
|
|
Your never actually creating an instance of myfoo , try changing your _tmain to:
int _tmain()
{
MFoo*myfoo = new MFoo( );
myfoo->ManagedDoSomeFoo();
return 0;
}
Gavin Taylor
w: http://www.gavspace.com
-- modified at 5:39 Wednesday 8th March, 2006
|
|
|
|
|
thanks guys, i thought it was something like that,but i mainly use vb.net so i get a little stuck with c++.
i have been trying to wrap this example, so i can practice for a much bigger program.
i have never done this before and the help on the net is a little vague, i need a very very basic walkthrough, because the ones i have found won't compile, and its hard enough trying to debug code that you dont really understand.
i know this much....
i have a class library(.net) called fooManaged and its automatical created fooManaged.h. and i created UnManaged.h
in the UnManaged.h file i have this code.....
#include iostream <br />
#include vcclr.h<br />
using namespace std;<br />
<br />
class Foo<br />
{<br />
public:<br />
Foo();<br />
~Foo();<br />
void DoSomeFoo();<br />
};<br />
<br />
Foo::Foo() <br />
{<br />
cout<<"Constructor called!"<<endl;<br />
}<br />
Foo::~Foo() <br />
{<br />
cout<<"Destructor called"<<endl;<br />
}<br />
<br />
void Foo::DoSomeFoo(void)<br />
<br />
{<br />
cout<<"Do something funny!"<<endl;<br />
cout<<"Burrrp!"<<endl;<br />
}
in fooManaged.h i have this code....
<br />
#pragma once<br />
using namespace System;<br />
<br />
namespace fooManaged<br />
{<br />
public __gc class MFoo<br />
{ <br />
private:<br />
Foo * _foo;<br />
public:<br />
MFoo();<br />
~MFoo();<br />
void ManagedDoSomeFoo();<br />
};<br />
MFoo::MFoo() <br />
{<br />
_foo = new Foo();<br />
}<br />
MFoo::~MFoo()<br />
{<br />
delete _foo;<br />
}<br />
<br />
void MFoo::ManagedDoSomeFoo() <br />
{<br />
_foo->DoSomeFoo();<br />
}<br />
<br />
}
the fooManaged.cpp file just has...
#include "stdafx.h"
#include "Unmanagedfoo.h"
#include "fooManaged.h"
#using mscorlib.dll
it all compiles...but there is a big linking error!!
Compiling...
fooManaged.cpp
Linking...
LINK : error LNK2020: unresolved token (0A000005) _CxxThrowException
LINK : error LNK2020: unresolved token (0A000019) free
LINK : error LNK2020: unresolved token (0A00001A) strlen
LINK : error LNK2020: unresolved token (0A00001B) memmove
LINK : error LNK2020: unresolved token (0A00001C) memcpy
LINK : error LNK2020: unresolved token (0A00001D) delete
LINK : fatal error LNK1120: 6 unresolved externals
i must be doing something wrong, some help with this will be very wecome
thanks
|
|
|
|
|
hi every1
will u plz help me on this ...
im creating a generic container class and im implemeting it using the (void*) pointer technique
but to add a search feature, the search function should compare two (void*) variables, i dont know how to do that!
i think memcmp could be used somehow but the problem that it needs a length parameter which is now available!!
thanks already
|
|
|
|
|
you are on the C++/CLI forum[^], while you question is for the Visual C++ forum[^]
next time, be careful...
and for you problem, do you code in C or C++ ?
because C++ provides templates, that may certainly interrest you...
|
|
|
|
|
oh im sorry for this mistake
anyway it doesnt really matter if its a c or c++ but for templates they are not compliant with the c++ standard so i think using the void* will be safer!!
|
|
|
|
|
|
Amr Shahin wrote: ut for templates they are not compliant with the c++ standard so i think using the void* will be safer!!
are you on drugs ?!
templates are part of and are defined in the standard !!!!!
hey,, i think you should really revise you judgement about templates, and learn a bit more about them...
|
|
|
|
|
Amr Shahin wrote: i think using the void* will be safer!!
Templates were not finalized until the mid to late 90s so compliers created before this may have a problem with them but as long as you stick to the basics and don't use partial template specialization and a few other features you will be fine on older compilers. I have been using templates for at least 5 years starting with VC6 (which is not fully compliant but very capable of using templates). void* is definitly not the way to go if you are using c++.
John
-- modified at 12:09 Tuesday 7th March, 2006
|
|
|
|
|
It looks like most questions for this forum are off topic...
John
-- modified at 9:16 Tuesday 7th March, 2006
|
|
|
|
|
John M. Drescher wrote: It looks like most questions for this forum are off topic...
true, but if people had a look at the admin note...
|
|
|
|
|
Although I have seen it in the lounge I did not even notice it in this forum today...
John
|
|
|
|
|
John M. Drescher wrote: It looks like most questions for this forum are off topic...
True, but i blame MS marketing for this. Most people consider CLI to be "command line interface", not "common language..." (what the heck is I for anyway?).
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Nemanja Trifunovic wrote: (what the heck is I for anyway?).
Common Language Infrastructure...
|
|
|
|