|
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
|
|
|
|
|
Hi Luc,
The property set simply sets a local field (c#):
private bool loadFlag;
public bool LoadFlag
{
get { return loadFlag; }
set { loadFlag = value; }
}
I have break points before the set and in the property but it's not getting as far as executing any code. The complete function is simply:
extern "C" BOOL __stdcall testFunction(HWND hWnd, void* pVoid, LPSTR pszProcess)
{
String ^caseId = "ABC12345678";
Dialogs::TestDialog ^testDialog = gcnew Dialogs::TestDialog(caseId);
testDialog->LoadFlag = true;
testDialog->ShowDialog();
return true;
}
I suspect this is more of a problem along the lines of marshalling types, i.e could "true" mean something unintended ?
Thanks,
Andy.
|
|
|
|
|
Hi Andy,
I'm not a C++/CLI guy, I do C# most of the time; however I see nothing wrong in your code.
AFAIK true is represented by an int having value 1 whatever the language is. Anyway the C# property would interpret its input either as false or as true.
I would suggest you use a try-catch in testFunction, and show the Exception.ToString() that results;
it may contain the necessary hint.
If that does not help, here are two more experiments I could suggest:
- try similar code in C# with and without LoadFlag=true;
- modify TestDialog and give it a SetLoadFlag() method, then try from C++.
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
|
|
|
|
|
Thanks for the reply Luc.
I've just worked it out and I'm sorry to say I should have spotted it !
The bool property was a late edition to the assembly and and older version has been (incorrectly) installed in the GAC without the property. The newer version was referenced in the project allowing it to compile and the new version was also in the run directory.
fuslogvw.exe showed in binding to the copy in the run directory so somewhere in the guts of it all it went bang because of the conflict.
After cleaning it all up it works fine.
Thanks for taking the time to look.
Andy.
|
|
|
|
|
I've been working my way out of the console apps and I am now trying to learn how to use windows forms in visual studio 2008.
Anyway, onward to the question.
I am trying to display a numerical value as text in a label on a windows form. I looked around for an answer on the internet and I found some, but I couldn't get them to work for me. So I decided to start from scratch and just ask this forum for help.
Here's the section of code I'm dealing with, I bolded my problem areas.
Oh and to avoid confusion, click this: http://img100.imageshack.us/img100/4479/form1w.jpg. Its a picture of my form with all of the variables and etc labeled.
private: System::Void numberDisp_Click(System::Object^ sender, System::EventArgs^ e)
{
numberDisp->Text = ticketNumber->Value
}
private: System::Void priceDisp_Click(System::Object^ sender, System::EventArgs^ e)
{
int tickNum = 0;
double price = 0;
tickNum = ticketNumber->Value;
if (locB->Checked == true)
{
price = tickNum * 75;
}
if (locP->Checked == true)
{
price = tickNum * 30;
}
if (locL->Checked == true)
{
price = tickNum * 21;
}
priceDisp->Text = price;
}
|
|
|
|
|
Hi,
when a Control needs a string (e.g. the Text property of a Label), and your value isn't a string yet, I suggest you use the ToString() method which exists for all objects. Most often there are several overloads, one without any arguments producing a standard string representation, and one or more accepting some formatting information.
Example: int.ToString("X8") would result in an 8-digit hexadecimal value.
BTW: I would rather write if (locP->Checked)... than if (locP->Checked == true)... although both have exactly the same meaning.
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
|
|
|
|
|
listBox1->SelectedItem = "---- SELECT! ----";
listBox2->SelectedItem = "---- SELECT! ----";
radioButton1->Checked = true;
radioButton2->Checked = true;
Hi guys, I need my application to start with some pre-selected items in the list boxes and radio buttons, and I can achieve this by manually pasting the code above between the lines of the code which is automatically generated by VS2008 (using Windows Forms). By doing this the program works however the GUI Design page gets really screwed up and I loose the ability to make any further editing!
Where do these attributes have to be inserted? I have tried in the main{} section but it returns an error.
Help please!!
|
|
|
|
|
In general, you shouldn't edit any designer-generated code.
I don't do Windows Forms, but I believe typically you'd do those kinds of
initializations in response to the Load event.
You can add event handlers from the properties pane for your form and or controls.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the advice, it works very well and the designer page is not affected.
It all needs to go into the Load event.
Cheers
|
|
|
|
|
Hi,
I am running through a problem and thought anyone here might help me out with this.
Here is my issue,
I am trying to convert an AVI ( 8 bits per pixel ) file into a stream of bmp files, though i am able to convert them the bmp images does not match the avi frames they are some what right shifted in a round robin way. Please let me know were i am going wrong. I am attaching the avi file and bitmaps of first 2 frames of the avi file, also attached is my code written in c++ on windows 2005 platform.
I converted the avi files into bmp frames using Irfan View and it worked fine.
Please let me know were i can i share my AVI file and generated BMP files.
Thanks
Santosh
|
|
|
|
|
Are you writing the BMP formatted data yourself?
A common error when creating BMP files is to not align rows of pixel
data on DWORD (multiple of 4) boundaries.
Also you need to write the header bytes correctly or BMP readers may
try to read pixel data starting from the wrong place in the data.
Can you post your writer code?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Please, anyone out there, can you explain clearly how to deal with Functions. I need more information on;
-create function,
-call function
-anything about functions and their applications.
Thanks!
Aloysius.
|
|
|
|
|
Visiolizer wrote: Please, anyone out there, can you explain clearly how to deal with Functions. I need more information on;
-create function,
-call function
-anything about functions and their applications.
You can deal with a function in different ways , like you can
Declare them : ();
Define them : () { }
&
Call them : x = ();
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
You sound like someone new to programming. A program is a set of statements, executed one after the other. Functions are a way to give a group of statements in a program a name of their own. You can then 'call' that function using the name, and the statements in the function are executed in place of the call.
Here's an example: Suppose you want to add one to a number, multiply the result by seven, and then divide that by two:
int number = 5;
number = number + 1;
number = number * 7;
number = number / 2; Now suppose you need to do this with several numbers. Typing the same lines of code over and over seems kind of dumb, so let's turn this into a C++ function:
int ProcessNumber(int number)
{
number = number + 1;
number = number * 7;
number = number / 2;
} and you can use this function like this:
num1 = ProcessNumber(5);
num2 = ProcessNumber(34);
num3 = ProcessNumber(-9); Basically functions are just a kind of shorthand for referring to a group of statements. Functions become really useful when you realize that they can call each other.
|
|
|
|
|
Hi,
you really should buy a book on the programming language of your choice, and study it from the first page till as far as you get, only then start programming something. That will teach you the essential terms and concepts much faster than anything else, explain things correctly and provide simple examples and exercises.
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
|
|
|
|
|
I am reluctantly new to VC++/CLI 2005. Home-Sweet-Home is VB - even VB5. Using VS 2005 I have two plroblems current.
a) How do I produce a pointer to an EXISTING user-defined type in C++/CLI. A search of MSDN and texts all give examples using gcnew.
b) My editor has lost the ability to show my main form in design format. The remaining forms are OK but the corresponding procedures do not wake up the main form in design format. It has the most on it and I hate the idea of starting afresh or working my way through the verbose code. I found one other on MSDN who had this problem, found no solution and has thrown VS2005 out (for other reasons as well). VS warns not to change the name and that has NOT been done. This has never happened to me using the VB or C# editors.
I'll be grateful for help. This 'adventure' has not been fun and I'll be glad when I get home again.
Regards, Ron
|
|
|
|
|
regnwald wrote: How do I produce a pointer to an EXISTING user-defined type in C++/CLI
C++/CLI uses handles (^) to point to managed types. So if you have a managed class Foo, pointer to foo will be
Foo^ fooPtr = gcnew Foo() Is your existing user-defined types are managed types? If not, you can use the normal pointer like
Foo* fooPtr = new Foo;
|
|
|
|
|
Thanks (again) for your fast reply. I HAVE ordered that book you sugested but it is yet to arrive. So, I'm still very ignorant. I read:
Foo^fooPtr = gcnew Foo()
as
poiter-to-thing-called-Foo named-fooPtr = new Foo()
and relating to a new instance of Foo() referenced by a pointer instead of a name. I don't want a new Foo(). I want a pointer to the Foo() that was instanced previously elsewhere. Have I completely misunderstood the syntax?
Regards
Ron
|
|
|
|
|
regnwald wrote: I don't want a new Foo(). I want a pointer to the Foo() that was instanced previously elsewhere.
Strange! So where are you keeping that pointer? If you could explain what you are trying to achieve, I think there will be better solution.
|
|
|
|
|
"Strange"? Oh dear, I must be way off.
Early in the project I instanced a type:
cdVersionInfo cdVI;
I first cleared it with:
memset(&cdVI,0,sizeof(cdVersionInfo));
After including "memory.h" this gave no errors.
memset() accepts &cdVI but VC++ 2005 does not. Yet I need a pointer to cdVI for a function RCStartSDK in a .dll. Using &cdVI in memset and my project compiles with no errors (I must check data in cdVI tonight) but using &cdVI in calling RCStartSDK gives a compiler error that using & is an anachronism.
The memset line comes from a VC++6 example of how to use the SDK. Imported and converted for VC+++2005 does not alter either code using of &cdVI and the exaple still works with both. But the same code in my project does not work. Even including the example's H file into my project does not help.
If I was at "AT HOME" I would say cdVIptr=VarPtr(cdVI). I have a (slightly) horrid feeling I need to change the first instance f cdVI to your suggestion. I still need to be able to clear the type and cdVIptr has to be global and I assume I set values:
cdVIptr^.SIZE = sizeof(cdVersionInfo);
or
cdVIptr*.SIZE = sizeof(cdVersionInfo);
depending on circumstances.
Am I struggling in the right direction or am I unable to see the jungle for the vines?
One day perhaps...
But its really hard going back to school at 72. I speak a litthe Italian, French and German, but the dialects always confuse.
Regards
Ron
|
|
|
|
|
hi guys,
I have a program that connect to mysql database in a remote location(speedhosting.co.cc). but when ever i execute the program it shows error.
connection state : driver closed undefined value data reader = undefined value
I am using VC++ .net to for this program and (using namespace MySql::Data::MySqlClient)
Kindly help me plz. Thank you.
Regards,
Thilek
|
|
|
|
|
How are you trying to connect I assume you are using the mysql data provider for .net if so what is you connections string sans the username and password
a programmer traped in a thugs body
|
|
|
|
|
Thanks for looking at my question,
I am wondering how I would use the ToUpper and ToLower functions on only part of a string in .net C++.
For example, I converted an inputted name to all caps for the purpose of comparing it. Now I need to display the name with only the first letter capitalized.
In short, I need to make "BRAD" to "Brad"
Note that the inputted name is not always the same, so however you can show me how to do this has to work with any inputted name.
Thanks for any help!!
|
|
|
|
|
TabascoSauce wrote: with only the first letter capitalized.
Sentence case? You can write code using SubString(), ToUpper() and ToLower(). Here it is.
String^ ConvertToSentenceCase(String^ input)
{
return (input->Length > 0) ? String::Concat(input->Substring(0,1)->ToUpper(),input->Substring(1)->ToLower())
: String::Empty;
} Other methid is to use TextInfo class and work with ToTitleCase method. Here it is
String^ ConvertToSentenceCase(String^ input)
{
using namespace System::Threading;
return Thread::CurrentThread->CurrentCulture->TextInfo->ToTitleCase(input);
} Hope that helps
|
|
|
|