|
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
|
|
|
|
|
|
Managed C++ executables can have a mixture of native and managed classes. Those classes that are managed have to be prefixed with __gc. The other classes use C++ usual notation.
Be carefull when doing this in dll. Net framework 1.0 and 1.1 have a serious bug when working with mixed code in dlls (dlls may hang - it is called the mixed dll problem). But in executables you can safelly mix code if you take into account the differences between managed and native code.
|
|
|
|
|
I have done lots of reading on the .NET framework and managed C++ but haven't done any development with either. I'm primarily a C++/MFC 6.0 developer and do some ASP/web stuff aside. My web development will move towards ASP.NET. A decision that's a no-brainer to me because of all the benefits and enhancements that come with ASP.NET.
I'm looking for people's opinion on writing shrink wrapped software using MC++ (or C#) and the .NET framework. To do, or not to do? I'm quite stuck on which direction to go, managed code vs. native code, for my next shrink wrapped, desktop application? I don't want to move to .NET just because it's cutting edge, new and exciting.
I don't need any security features provided wit .NET, deployment isn't that difficult now anyway, I don't do mobile devices or multiple platforms, and integration with 3rd party applications is all done with delimited files. From a functional/security standpoint, there's little reason to move to .NET from what I can tell, other than possible productivity gains. Even with productivity gains, I have so much reusable C++/MFC code from other applications, I don't see enhanced productivity being that great.
I've read opinions that say to stay away from MC++ and go C# or VB.NET if developing under .NET. I've read opinions that say stay away from .NET with shrink wrapped, desktop software. Both opinions were shallow with little supporting arguments. I hope to get a more in depth discussion started here.
The fine print:
1) Should shrink wrapped, desktop software be developed using .NET? (i.e. apps like a text editor, graphics editor, or other file-based application.)
2) If so, should reusable C++ code be converted to MC++ or be rewritten using C# or VB.NET?
Thank you for your support. B&J
|
|
|
|
|
For all it is worth, I am a former developer of Microsoft Excel and am using C# to develop shrink-wrapped desktop software.
The plus:
1) Garbage collection reduces an entire class of errors
2) Performance is actually quite good. One thing that you often don't hear is that code written in C# can actually be faster than C++ in many cases because of
a) Extensive inlining,
b) use of the __fastcall convention,
c) ultrafast heap allocation
d) sizeable library
3) Very good exception handling
4) You are going to develop your software much faster
The one bad thing is the omission of some of the document infrastructure of MFC and the number of third-party support for MFC.
Thanks,
Wes
|
|
|
|
|
Please take a look at WTL. As for the argument of C# being faster, it depends on what you are doing - if you accessing database, the speed is actually not much dependent on the application but by the database provider access protocol and other factors.
I have just completed an MC++ GIS component, the GDI+ speed is so disappointing. However, using the direct COM version with GDI where necessary, I got a manageable speed.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Paul Selormey wrote:
I have just completed an MC++ GIS component
An article possibility??
-Nick Parker
|
|
|
|
|
Nick Parker wrote:
An article possibility??
It is a company work, however, I might find time to share some points and experience if this is what you mean.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Paul Selormey wrote:
It is a company work, however, I might find time to share some points and experience if this is what you mean.
It sounded interesting, sure, write something up.
-Nick Parker
|
|
|
|