|
Thank you very much!
Yes I know about the speed bumps but I'm careful with every transition (mostly from windows forms to unmanaged code)...
Best regards
Hansjörg
|
|
|
|
|
The only way I could get native static objects to work in managed code was to place them inside of static functions or static methods. For example:
#pragma managed(push, off)
using std::wstring;
class Foo
{
public:
static const wchar_t* State(const wchar_t* value = 0)
{
static std::wstring state= L"";
if (value != 0)
state = value;
return state.c_str();
}
};
#pragma managed(pop)
using namespace System;
int main(array<System::String ^> ^args)
{
String^ str1 = gcnew String(Foo::State());
Foo::State(L"Hello!");
String^ str2 = gcnew String(Foo::State());
Console::WriteLine(str1);
Console::WriteLine(str2);
return 0;
}
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
|
Issue #2: Have you tried manually boxing the zero?
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hello!
I have this code:
(...)
static double U[5];
(...)
And, when i compile i see this error:
error C4368: cannot define 'U' as a member of managed 'bojoo::Class1': mixed types are not supported
How i fix it?
Thank´s!
Rapbs
|
|
|
|
|
Rui A Sousa wrote: How i fix it?
I would like to clarify what you are asking for. Do you want someone to tell you how to fix the code or, do you want to understand the issue so that it will never be a problem for you again?
|
|
|
|
|
One feature in Visual Studio I find useful is the pressing the F1 key on error messages I don't
understand
For example - your error shows me:
"You cannot embed a native data member in a CLR type. You can, however, declare a pointer to a native type and control its lifetime in the constructor
and destructor and finalizer of your managed class (see <mshelp:link tabindex="0" keywords="0d09d3f1-13a0-4041-8178-402aad667edd">Destructors and Finalizers in Visual C++
for more information)."
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
2 classes which are dialogues.
On the 1st dialog, I have button that when pressed opens another dialog. I can't work out how to make the second one modal.
I'm calling the second Dialog boxes show() method in the DlgProc method as below.
LRESULT CALLBACK ExodusDisplayOptions::DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){<br />
switch(message)<br />
{<br />
case WM_INITDIALOG:<br />
{<br />
}<br />
break;<br />
case WM_DESTROY:<br />
PostQuitMessage(0);<br />
break;<br />
case WM_COMMAND:<br />
{<br />
switch (LOWORD(wParam))<br />
{<br />
case WM_CLOSE: <br />
return (TRUE);<br />
break;<br />
case IDC_CLOSE:<br />
EndDialog(hDlg, LOWORD(wParam));<br />
return (TRUE);<br />
break;<br />
case IDC_BUTTONDISPLAY:<br />
ExodusHazardDisplayOptions *haz = new ExodusHazardDisplayOptions(m_this, m_opts);<br />
bool i = haz->Show();<br />
break;<br />
<br />
<br />
}<br />
<br />
<br />
} <br />
break;<br />
default:<br />
return DefDlgProc(m_this, message, wParam, lParam);<br />
}<br />
return 0;<br />
}
Any ideas?
|
|
|
|
|
gunner_uk2000 wrote: Any ideas?
You're in the wrong forum
What does "haz->Show()" do? Is it creating a modal dialog? For a modal dialog
you need to call one of the DialogBox___() APIs.
Off topic... the "case WM_CLOSE " in response to WM_COMMAND looks suspicious.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi All
I am creating a managed wrapper class for a c++ unmanaged class.While I am calling a function in managed class and passing a short paramater as reference
1.short MCDPTAdminClass::listPrinters() //managed class
2.{
3. m_CDPTAdminClass->listPrinters(&numPrintersFound);
//m_CDPTAdminClass object of unmanaged class and short numPrintersFound
return numPrintersFound;
}
I am getting an error "Can not convert from short __gc* to short*" at line "3"
Can anyone help me to resolve this problem .
thanks in advance
|
|
|
|
|
Thanks for all the fish wrote: Can anyone help me to resolve this problem
I would like to clarify what you are asking for. Do you want someone to tell you how to fix the code or, do you want to understand the issue so that it will never be a problem for you again?
|
|
|
|
|
Thanks for all the fish!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Thanks for all the fish!
Does that have some kind of religious significance?
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
George L. Jackson wrote: Does that have some kind of religious significance?
Only in my religious commitment to keeping led mike's fish-filet analogy alive!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
HeHe! I saw the original posts!
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Is it possible to call into a .NET class library from a VC60 C++ app? If yes, how?
I wanted to create a middle layer between C++ app and .NET class library - sort of a wrapper for .NET class library. Towards that end, in VS2005, I created a C++ Win32 Dll. I have turned on CLR option from Project->Properties>Configuration. But in this project, I couldn't figure out how do I instantiate ClassLibrary and make calls into it. Can someone please enlighten?
Thanks.
None
|
|
|
|
|
concoran wrote: Can someone please enlighten?
It sounds like this is your initial use of C++/CLI? If so I recommend learning about it first before you approach your project. There are almost endless articles, tutorials and sample/example projects available here and on MSDN to educate you about the power of C++/CLI.
|
|
|
|
|
Hi Led,
Yes, I am new to CLI, but not to C++. I am also new to Codeproject. Can you pls point to where I can find articles on this website?
Thanks in advance.
None
|
|
|
|
|
concoran wrote: Can you pls point to where I can find articles on this website?
On the "Articles" menu (it's between "Hellp" and "Message Boards") click the "Site Directory" link
|
|
|
|
|
Hi, I'm using Visual Studio 2005 C++/CLI. I have been surfing for information on zooming using CLI. The SetWindowsExt() and SetViewportExt() functions do not seem to be available any more. If anyone has a link to an article or can at least point me in the right direction it would really help.
Thanks,
Buck
|
|
|
|
|
Hi Buck,
if you want to modify things you paint yourself (say inside OnPaint),
then you can use the transform methods of the Graphics class; they let
you set translation, rotation, scaling (or an enire matrix), then do
the paint stuff as before.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi Luc,
Here is the code that allows me to use the mouse to draw a rectangle around an area of the display that I want to fill the display with, hence zooming. The aspect ratio is kept constant so if the rectangle is too high or too wide then it adjust the heighth or width accordingly. The Translate function positions the origin. The Scale function sets the scaling in the x and y directions. This TransformPointsExample function is called from OnPaint(PaintEventArgs^ e).
private: void TransformPointsExample(PaintEventArgs^ e)
{
float aspect_ratio = (float)nDisplayHeight / nDisplayWidth;
float zoombox_height = (float)zoomRectEndPos.Y - zoomRectStartPos.Y;
float zoombox_width = (float)zoomRectEndPos.X - zoomRectStartPos.X;
if(zoombox_height / zoombox_width > aspect_ratio)
zoombox_width = zoombox_height / aspect_ratio;
else
zoombox_height = zoombox_width * aspect_ratio;
float y_scale = (float)nDisplayHeight / zoombox_height;
float x_scale = (float)nDisplayWidth / zoombox_width;
Matrix^ myMatrix = gcnew Matrix();
myMatrix->Translate(-(float)zoomRectStartPos.X, -(float)zoomRectStartPos.Y);
myMatrix->Scale(x_scale, y_scale, MatrixOrder::Append);
e->Graphics->Transform = myMatrix;
}
Buck
|
|
|
|
|
Hi Buck,
thanks for the update. Any questions?
You did not have to create a Matrix, Graphics.TranslateTransform() plus
Graphics.ScaleTransform() would have given same result and avoid an object.
As it is now you should do myMatrix.Dispose() when OnPaint is done!
[CORRECTION] See the next two replies by Mark: in C++/CLI Dispose() can not be
called directly, but a delete is in order [/CORRECTION]
-- modified at 5:28 Thursday 30th August, 2007
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: you should do myMatrix.Dispose() when OnPaint is done!
Or for C++ consistency, use
delete myMatrix;
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: delete myMatrix;
I'm not fluent in C++, but the way I understood it is:
- delete undoes a new
- managed objects are created with gcnew, are garbage collected, and
should have their Dispose() method called if the class offers it.
The original code had: Matrix^ myMatrix = gcnew Matrix();
and Matrix class offers Dispose()...
greetings
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|