|
Look at the System::Convert class and it's ToInt32 methods...
Hawaian shirts and shorts work too in Summer.
People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage...
-Anna-Jayne Metcalfe on Paintballing
|
|
|
|
|
Hi!
I'm writing a Managed C++ class library to be used by a C# client, and I have a method which prototype should look like that from C#:
MyClass.Method(string Param1, out int Param2);
Problem is, I do not clearly understand how to declare an "out" parameter in Managed C++. I tried a pointer-on-int, as I used to do in COM with the [out] attribute, but it doesn't work (IntelliSense on the C# side wants an int* too!)
I could use a reference of course, like that:
public __gc class MyClass
{
public:
void Method(System::String __gc *Param1, int &Param2) {... }
}
Not sure it works though and then the C# prototype would probably become "ref int Param2".
Is there any clever solution to this?
R/
|
|
|
|
|
ralfoide wrote:
public __gc class MyClass
{
public:
void Method(System::String __gc *Param1, int &Param2) {... }
}
The purpose of a ref parameter in C# is where the callee function assigns the value, which is exactly what your void Method(System::String __gc *Param1, int &Param2) function allows to happen to Param2 .
-Nick Parker
|
|
|
|
|
I beg to differ, but my understanding is that a "ref" is used when the called function will modify the value. An "out" seems preferable if the called function is just returning parameters.
My sample prototype was of course simplified. My function returns several parameters, and rather than returning a struct I prefer to use out parameters.
Example of C# prototype I want:
MyClass.MyMethod(string inValue, out int Param1, out int Param2, out int Param3);
So far I got it to work using "ref" if I declare the Param1..3 above using int __gc * in MC++:
This MC++ real prototype in the class library:
MyClass::MyMethod(System::String __gc* inValue, int __gc* Param1, int __gc* Param2, int __gc* Param3);
is seen like this from the C# client:
MyClass.MyMethod(string inValue, ref int Param1, ref int Param2, ref int Param3);
Ideally I'd like out parameters. If not possible, well too bad
R/
|
|
|
|
|
|
Not sure if this will help much, but I think that ref and out perform pretty much the same job, they just set a different kind of contract.
When using out you are effectively saying that the method is responsible for initialising and setting the contents, whereas with ref the calling code is responsible.
What happens if you try and use the out keyword from the C# code? Does the compiler throw up an error?
--
Paul
"Put the key of despair into the lock of apathy. Turn the knob of mediocrity slowly and open the gates of despondency - welcome to a day in the average office."
- David Brent, from "The Office"
MS Messenger: paul@oobaloo.co.uk
|
|
|
|
|
Why don't you use something like
void foo2( [out] short *value);
|
|
|
|
|
I'm trying to use managed C++ - I know this is the wrong forum but I get no response in the C++ forum.
I'm trying to use old C style structures to read in structured blocks of data from a file and am having no luck. For instance, here's my structure:
[StructLayout(LayoutKind::Explicit)]
__value struct PRE_HEADER
{
public:
[FieldOffset(0)]Byte fileType;
[FieldOffset(1)]UInt32 timeStamp;
[FieldOffset(5)]Int16 numIndexes;
[FieldOffset(7)]Byte padding;
};
Is there some way to read this in, maybe with streams like so:
PRE_HEADER ph;
int blocksize = sizeof(ph);
Byte tmpBuf __gc[] = new Byte __gc[blocksize];
FileStream* fs = File::Open(blah, blah, blah...);
fs->Read(tmpBuf, 0, blocksize);
And then somehow cast "tmpBuf" to be a PRE_HEADER type so I can access the members like you used to be able to do in C/C++??? These managed streams need to have a managed Byte buffer. I tried doing the following:
ph = reinterpret_cast<pre_header>(tmpBuf);
but the compiler isn't happy. I've tried different ways to create the variable "ph" on the managed heap, but because I have a "struc" there's no "new" operator, which I think is causing the unresolved external link errors looking for operator new().
There MUST be some way to do this. It's all so easy with C++ streams. You just make a buffer and pass it to the Stream::Read() function and cast it as your data type and away you go.
Thanks for any help - I"m pulling my hair out with this...
Mark.
|
|
|
|
|
|
Nick.
I tried dynamic_cast but I get a compiler error saying "invalid target type for dynamic cast" (with the capital p
I also tried reinterpret_cast and I get this error:
error C2440: 'reinterpret_cast' : cannot convert from 'unsigned char __gc[]' to 'PRE_HEADER'
I realize a managed array isn't going to be a block of memory - but I can't believe they've left us out in the cold when it comes to this kind of thing. For me it's been the main-stay of my file i/o for data collection because it doesn't tie the file to any language (i.e. through serialization stuff).
Mark.
Mark Malin
(00==[||]==00)
|
|
|
|
|
|
A managed C++ program executes under the .net runtime, so all the rules that apply for normal .net apps, also apply for an application written in mc++, but it gets interesting when you mix both managed and unmanaged code.
If you want to know more on garbage collection/clr, check out msdn, it has tons of docs. on that subject.
Cheers,
Kannan
|
|
|
|
|
I used .NET 2003 VC++ to create a ATL .EXE project. I want add a Web Reference into this project, when I enter the Web Service URL in the "Add Web Reference Dialog", I can get the Web Service Description, but when I click "Add Reference button, I get error message :
error SDL1000 : Not assigned error.
error SDL1002 : failure in generating output file: "WebCtrlService.h"
Who can help me ?
Thanks.
|
|
|
|
|
Does anybody know of any good proposals for a final year undergraduate
computer science project. I would like something i could implement in the
new Visual Studio.net.
James
|
|
|
|
|
i want to know how to use "switch" statement in mfc applications. spcially in the toolbars, where the user can press
one toolbar->circle->draw circle. user can repeat or select new retangle/shape
same toolbar->rectangle->draw recnagle. user can repeat or select new circle/shape
same toolbar->particualr shape->draw that shape. user can repeat or select new retangle/circle
e.g.
switch(toolbar){
case(circle)
{
//draw it}
case (retangle)
{
//draw it
}
case(paricular shape)
[
//draw it
}
}
thanks
shanila
|
|
|
|
|
public __gc class Message
{
private:
TIBRVWrap::MSG __nogc* m_pNativeMsg;
public:
__property void set_ReplySubject(const String* Sbjt)
{
// m_pNativeMsg->SetReplySubject(....);
}
};
public __abstract __gc class Transport
{
public:
Transport(){ }
void Send(Message* msg)
{
// I need to access the msg->m_pNavtiveMsg directly
// How is it possible.
}
};
|
|
|
|
|
public __gc class Message
{
public private:
TIBRVWrap::MSG __nogc* m_pNativeMsg;
public:
__property void set_ReplySubject(const String* Sbjt)
{
// m_pNativeMsg->SetReplySubject(....);
}
};
public __abstract __gc class Transport
{
public:
Transport(){ }
void Send(Message* msg)
{
// I need to access the msg->m_pNavtiveMsg directly
// How is it possible.
}
};
|
|
|
|
|
Sounds like a job for the internal keyword, not sure if it is in MC++ though...
<a TITLE="See my user info" href=http:
|
|
|
|
|
Hello group..
i need a console application in vc ++ to read and write informations in registry..
someone can help me ?
regards
leandro
|
|
|
|
|
|
thanks to see my question~
I hope to use MFC to browse remote directory
my ideal is write one server, one client
when client ask server`s directory
i let server transfer local "BROWSEINFO" to client
and client use it borwse directory function to read
server`s "BROWSEINFO"
but i can`t use socket to transfer "BROWSEINFO" ?
i don`t know what type "BROWSEINFO" is.
or what I think is total worng?
thanks~
Chai-Yuan, Young
chai_yuan@msn.com
|
|
|
|
|
Please use the Visual C++ forum for MFC questions. Here we concentrate on MC++ related isssues.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
you can use the WinSOCK send() to send the BROWSEINFO structure, and use recv to recieve the BROWSEINFO structure from the server.
|
|
|
|
|
hi guys,
I have a doubt..
How to use VC++6.0(Unmanaged classes) in managed C++ Form application?
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|