|
Hi J_E_D_I,
put
sep=<separator symbol="">
in the very first line, then it works even with a double click.
Works well except with CRLF
regards
CBM 6502
|
|
|
|
|
Hi J_E_D_I,
put
sep=<separator symbol>
in the very first line, then it works even with a double click.
Works well except with CRLF
regards
CBM 6502
|
|
|
|
|
Hi - I've saved a System.Drawing.Image to a file stream from C# and now I'm trying to load it in Managed C++...
I have some other data that is included inbetween the bitmap data in the filestream and when I blt the surface to the backbuffer, the surface thats supposed to hold the bitmap data is entirely black. :-/
Tiles[i].Init(lpDD7);
bool Walkable = br->ReadBoolean();
MemoryStream^ ms = gcnew MemoryStream(br->ReadBytes(TILE_BITMAPSIZE));
Image^ bm = Image::FromStream(ms, true, true);
Graphics^ g = Graphics::FromImage(bm);
IntPtr^ hDC = g->GetHdc();
HDC src = static_cast<HDC>(hDC->ToPointer());
HDC dst;
Tiles[i].Walkable = Walkable;
Tiles[i].Surface->GetDC(&dst);
BitBlt(dst, 0, 0, 32, 32, src, 0, 0, SRCCOPY);
Tiles[i].Surface->ReleaseDC(dst);
Heres the INIT function
void Init(LPDIRECTDRAW7 lpDD7)
{
DDSURFACEDESC2 ddsd;
INIT_DXSTRUCT(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = 32;
ddsd.dwHeight = 32;
HRESULT hr = lpDD7->CreateSurface(&ddsd, &Surface, NULL);
}
Thanks.
|
|
|
|
|
Solved the problem...
the Bitmap class can be cast into an HBITMAP & then selected as an HDC to be copied into the surface.
Heres the fixed code:
MemoryStream^ ms = gcnew MemoryStream(br->ReadBytes(TILE_BITMAPSIZE));
Bitmap^ bm = gcnew Bitmap(Image::FromStream(ms, true, true));
HBITMAP hbm = (HBITMAP)bm->GetHbitmap().ToPointer();
HDC src = CreateCompatibleDC(NULL);
SelectObject(src, hbm);
HDC dst;
BitBlt(dst, 0, 0, Width, Height, src, 0, 0, SRCCOPY);
|
|
|
|
|
i have got application settings stored in the registry, i want to read the registry only once and store the settings in an array of struct globally and use them through out the application.i tried it but C++/CLI doesnt allow it,how do i do it, can someone tell me an alternate way.
Naveen
|
|
|
|
|
What do you mean C++/CLI doesn't allow it?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
i mean managed code doesn't allow to declare array of structs as global.
if possible can u please guide me
thank you
Naveen
|
|
|
|
|
Read about Singleton pattern.
|
|
|
|
|
i tried to read the documents ,but i couldn't understand. Below is the code i tried to use but it doesn't work. can u please help me do it
public ref struct HostSetting
{
static String ^HName;
static String ^HAddr;
static Collections::ArrayList ^cardType = gcnew System::Collections::ArrayList();
static String ^HCommtype;
static String ^HMsgType;
static String ^HPriority;
static String ^oldHostName;
};
array <hostsetting^>^ hostList = gcnew array<hostsetting^>(5);
Naveen
|
|
|
|
|
Ok. Here is a sample of singleton.
ref class MySettings
{
public:
static property MySettings^ Instance
{
MySettings^ get()
{
if(!instance)
LoadSetting();
return instance;
}
}
private:
static void LoadSetting()
{
instance = gcnew MySettings();
}
static MySettings^ instance;
}; You can use it like
MySettings^ currentSettings = MySettings::Instance; Here we have persisted the value in a static field and this value will be available until your application domain unloads.
If your application is multi-threaded, you need more precautions when using singleton.
|
|
|
|
|
thanks a lot.
but how can i have an array of class and how to access a particular array element and where shall i declare all my structure elements.i am new to c++/cli i am not able to understand the code u have written, i had posted the code, can u please explain it in that terms.
Sorry for the trouble.
Naveen
|
|
|
|
|
naveen_bij wrote: but how can i have an array of class and how to access a particular array element
Assume you have a class named Foo. Array of Foo can be created like
array<Foo^>^ fooArray = gcnew array<Foo^> {gcnew Foo(),gcnew Foo()}; You can use indexer to access the elements. Like
Foo^ first = fooArray[0]; naveen_bij wrote: i am new to c++/cli i am not able to understand the code u have written, i had posted the code, can u please explain it in that terms.
Code which I have posted is trivial. You can easily understand it and merge it with your own code. Just add your properties to it and write code in LoadSetting method.
|
|
|
|
|
is the below code correct and when ever i load the parameters from registry, i load the whole array of class.
public ref class HostSettings
{
public:
static String ^HName;
static String ^HAddr;
static Collections::ArrayList ^cardType = gcnew System::Collections::ArrayList();
static String ^HCommtype;
static String ^HMsgType;
static String ^HPriority;
static String ^oldHostName;
static property HostSettings^ Instance
{
HostSettings^ get()
{
if(!instance)
LoadSetting();
return instance;
}
}
private:
static void LoadSetting()
{
instance = gcnew HostSettings();
}
static HostSettings^ instance;
};
array<HostSettings^>^ HostList = gcnew array<HostSettings^> (5);
i want the whole array to be available till the application unloads
this is the error i am getting when i do a global class array declaration
'HostList' : global or static variable may not have managed type 'cli::array<type> ^'<br />
1> with<br />
1> [<br />
1> Type=HostSettings ^<br />
1> ]<br />
1> may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap</type>
Naveen
|
|
|
|
|
I have converted my VC++ project to Common Language Runtime Support (/clr).
After this i find debugging(F5) calculation is too slow.
But in release mode there is no such problem.
Any solution for this problem?
|
|
|
|
|
KASR1 wrote: Any solution for this problem?
Don't run in the debugger?
Just don't do any serious performance profiling when running in the debugger
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
some simple manual code optimization may (or may not) solve such problems. Here is a typical example (using C# syntax):
Bitmap bm=new Bitmap(otherBitmap);
for (int x=0; x< bm.Width; x++) {
for (int y=0; y< bm.Height; y++) {
}
}
in debug mode bm.Height will be evaluated for each and every pixel, possibly costing more CPU cycles than the actual pixel operation. Replace the above by:
Bitmap bm=new Bitmap(otherBitmap);
int height=bm.Height;
for (int x=0; x< bm.Width; x++) {
for (int y=0; y< height; y++) {
}
}
and it will run much faster in debug.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
ifstream INPUT ("INPUT.csv");
INPUT << Cell1;
INPUT.close();
ofstream OUTPUT ("OUTPUT.csv");
OUTPUT << Heading1;
OUTPUT.close();
Any body could please tell me what are the C++/CLI equivalents for the INPUT / OUTPUT manipulators above?
Many thanks.
|
|
|
|
|
|
Thanks a million, that was an excellent source of info.
It all works apart from the AddText function below.
void AddText( FileStream^ fs, String^ value )
{
array<Byte>^info = (gcnew UTF8Encoding( true ))->GetBytes( value );
fs->Write( info, 0, info->Length );
}
I have added
System::IO:: before
FileStream but the compiler still returns an error regarding the UTF8Encoding...
|
|
|
|
|
Try this
array<Byte>^ info = System::Text::Encoding::UTF8->GetBytes(value);
|
|
|
|
|
HI,
I never wrote managed C++ code before.
And now i need to write something and after thinking i decided to write it in C++ and not in c#.
I'm using visual studio 2008 - and when i add some class i can choose between managed class or not managed class.
1 - Is not managed class is actually native ?
2 - I don't know when to choose managed class and when to choose not managed class.
3 - What about virtual destructor ? is Garbage collector work like in C# in those cases ?
Thanks for the help
|
|
|
|
|
Yanshof wrote: 1 - Is not managed class is actually native ?
C++ classes that aren't managed are typically called native classes, yes.
Yanshof wrote: 2 - I don't know when to choose managed class and when to choose not managed class.
Maybe depends on where you'll use the class...
A native class is native to Microsoft Visual C++ code.
A managed class is a class that follows/implements all the rules governing
classes for the Common Language Runtime (CLR), just like the classes in the
.NET framework. That makes managed classes usable by any CLR implemented
language - C#, VB.NET, etc.
Yanshof wrote: 3 - What about virtual destructor ? is Garbage collector work like in C# in those cases ?
The garbage collector is part of the .NET framework, so yes it works the same.
Destructors/Finalizers in C++ are a little different than in C#. They are called by
the framework the same way but the language syntax is different. Read carefully:
Destructors and Finalizers in Visual C++[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yanshof wrote: Is not managed class is actually native
Depends on what you mean by native. Managed class instances will be allocated on managed heap and will be controlled by runtime.
Yanshof wrote: I don't know when to choose managed class and when to choose not managed class.
Most of the people use C++/CLI for creating managed wrapper for unmanaged classes. If you use C++/CLI, you don't need to use unmanaged classes. Always try to use managed classes..NET framework class library is richer than standard C++ library. So you hardly need to use unmanaged classes in C++/CLI.
Yanshof wrote: What about virtual destructor ? is Garbage collector work like in C# in those cases ?
Garbage collector is part of .NET framework and it works well with managed C++. It will work only managed types. If you allocate memory for a unmanaged class, you need to explicitly remove it and garbage collector won't take care. Consider the following code,
ref class ManagedFoo
{
};
class UnmanagedFoo
{
};
int main(array<System::String ^> ^args)
{
ManagedFoo^ managedFoo = gcnew ManagedFoo();
UnmanagedFoo* unmanagedFoo = new UnmanagedFoo();
delete unmanagedFoo;
return 0;
}
|
|
|
|
|
Hi,
I'm hoping this is a really simple one but it's got me stumped.
I'm new to managed C++ so forgive me if it's a stupid question.
I have class library written in C# that contains a dialog. I am trying to instantiate the dialogs class, set a boolean property to true and the call the dialog ShowDialog method.
Here's the code:
String ^caseId = "ABC12345678";
Dialogs::TestDialog ^testDialog = gcnew Dialogs::TestDialog(caseId);
testDialog->LoadFlag = true;
testDialog->ShowDialog();
If I comment out the property set every thing works fine:
String ^caseId = "ABC12345678";
Dialogs::TestDialog ^testDialog = gcnew Dialogs::TestDialog(caseId);
testDialog->ShowDialog();
The exception I get is presented only at runtime and before the breakpoint I placed at the function entry point is hit and only when I have it set to the debug session to break on all exceptions:
Microsoft C++ exception: [rethrow] at memory location 0x00000000..
Can anyone help ?
Thanks,
Andy.
|
|
|
|
|
Hi,
if testDialog->LoadFlag = true; is causing problems, shouldn't you be showing some code of the class involved, i.e. TestDialog.LoadFlag and more?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|