|
numOfBits is always bigger than 3, so it's not a problem.
Case 2 is not skipped entirely because aux_trellis1c[2] and aux_trellis1d[2] are filled with appropriate nodes (node5 and node6). I worry why aux_trellis1a[2] and aux_trellis1b[2] are not filled when i has already reached value 3.
"i" is not changed by any other object, it is only internal argument for for loop.
Sorry for so lame description, I'm bad at programming, that is why I have stupid problems and probably the solution is very easy but I just can't see it:/
|
|
|
|
|
please use PRE tags when showing code snippets; they preserve indentation and improve readability. You could still edit your existing message!
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
OK, I don't see how it would be possible to execute the bottom half of a case.
I can only suggest you set a breakpoint at the first statement of case2 and single-step from there (assuming it goes wrong the very first time).
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
Hi,
I planed to create a form application with menubar and toolbar. I should let the program have the scroll bar, so I setted the AutoScroll = True, AutoScrollMinSize=(2000, 1000). And then the form application did have the scroll bar (both vertical and horizional).
However, there was a problem when I scrolled down the scroll bar, the menubar and the toolbar were scrolled down too. So when I scrolled the scroll bar, the menubar and the toolbar disappeared. very strange!
I had written some winform programs with VC++ 6.0 before, those components(menubar and toolbar) will not be disappeared when scrolling. Why the c++/cli winform program cannot work?
BTW, I'm using VC++ Express 2008. Maybe it's a very simple question, Can any kind man help me and tell me why?
Thanks in advance.
Joul
|
|
|
|
|
try this:
- fill the Form with your menubar, your toolbar, and a Panel (if the Form is resizable, make the Panel anchored or docked).
- make the Panel scroll (ScrollBars property).
- add all actual content to the Panel, not the Form.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thanks for your kind reply.
hello!
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
BTW,I did some test right now, I added some painting codes in panel's on_paint function. However, the painting can not be double buffered, and the panel's double buffered property is private.
If I want to do some painting in the panel, there are some blinks when painting.
How about your idea about this?
Thanks.
Joul
|
|
|
|
|
There are two ways I know of:
1.
you derive your own DoubleBufferedPanel from the normal Panel, then in its constructor you can set the double-buffered property (as it is protected). Once you build a project with such DoubleBufferedPanel class present (but still unused), Visual Designer should have it available and now you can replace the Panel by a DoubleBufferedPanel.
2.
you can change the properties of a regular Panel at run-time, something akin to:
panel.SetStyle(System.Windows.Forms.ControlStyles.DoubleBuffer,true);
panel.SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint,true);
panel.SetStyle(System.Windows.Forms.ControlStyles.UserPaint,true);
oanel.UpdateStyles();
This also works on pre-2.0 .NET versions where Control.DoubleBuffered didn't exist.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi,
I did some test again, but panel.SetStyle is the private function, and I can not use that function.
For the first way, I can make a DoubleBufferedPanel class, but it's not convinent for visual designer.
I don't know if there is another way. Thanks.
hello!
|
|
|
|
|
Indeed, SetStyle isn't public either, my mistake. So you have to create your own Panel.
Here[^] is an article where I did exactly that; there is a download near the end. It is in C#, I trust it would be basically the same in C++//CLI. Getting Visual Designer to find the new controls depends on a number of factors, I don't think I know them all; one is your code has to compile; another may well be the new Control has to be the first (or only?) class in its source file.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi Luc,
I had created a user constrol derived from panel class. and it's easy to add the new Control to the Visual Designer.
I provide a method named setDB to set if the panel can be doublebuffered. And it works.
Thanks for your kind help.
BTW, I had read your article about animation demo, it's greate.
Joul
|
|
|
|
|
Hey guys,
I have a question that's been plaguing me for a day or so. I'll try to explain as best as possible. No code this time, just some general questions.
I have a hierarchy of Windows forms, MainForm->AdminForm->JobDetailsForm. JobDetailsForm requires objects from MainForm, and AdminForm is just a middle man. Is there a slick way to get information from an object in MainForm to JobDetails form without passing the object through AdminForm? The object is an ArrayList of Objects called Users. I set information in the MainForm, and then I get that information inside of JobDetailsForm. Currently I'm doing something similar to
Pseudo Code:
MainForm
ArrayList users;
...
new AdminForm(users);
AdminForm
...
//no operations on users
new JobDetailsForm(users)
JobDetailsForm
...
//some operations on users
AdminForm has no use for users, it simply displays some information unrelated to users. If possible, I'd also like the operations preformed in JobDetailsForm to be reflected in the users object used in MainForm. I'm thinking a global or static variable could solve this, but from what I understand, there are no global or static variables in managed C++/CLI. Any ideas or suggestions?
[Insert Witty Sig Here]
|
|
|
|
|
VonHagNDaz wrote: I'm thinking a global or static variable could solve this, but from what I understand, there are no global or static variables in managed C++/CLI.
If you choose that route, you can have a ref class with a static constructor and static member methods/properties/fields...How to: Define Static Constructors in a Class or Struct[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Try something like this...
String ^temp = "5/26/2011";
DateTime start;
if (DateTime::TryParse(temp, start))
{
}
...or this...
String ^temp = "5/26/2011";
try
{
DateTime start = DateTime::Parse(temp);
}
catch (Exception ^)
{
}
Mark Salsbery
Microsoft MVP - Visual C++
modified on Monday, May 16, 2011 2:32 PM
|
|
|
|
|
That works! I'm a bit confused as to why your code works and mine doesn't. What is the difference between SomeDateTimeObject.Parse, and DateTime::Parse?
[Insert Witty Sig Here]
|
|
|
|
|
All the Parse() methods are static (AFAIK) so they return a new DateTime object instead of altering the one you were calling Parse() on.
This would have worked;
start = start->Parse(temp);
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I see, MSDN wasn't too clear on that. It lead me to believe temp would be modified. Thank you, 5's for both.
[Insert Witty Sig Here]
|
|
|
|
|
Hi,
I've got this problem and I don't try to solve it.
I'm using Microsoft Studio 2008 and I want to build a managed application.
This application uses a C unmanaged library.
In particular the library function that I must use is:
error_status TED_PixRad_RegisterEventCallback( eventCallback_t eventCallbackProc,void* customData = NULL ).
(I must use it to hook the event returned by a device).
This function has a callback function parameter with this syntax:
typedef void (*eventCallback_t)( const event_id eventID, const Event *eventData,void* customData );
I' ve found that I must build a wrapper class to use my managed application and the unmanaged library.
I try to build a wrapper class:
file wrapper.h:
#pragma once
#include "stdafx.h"
#include "gcroot.h"
namespace Pixium {
using namespace System;
using namespace System::Runtime::InteropServices;
void cdeclEventCallback(const event_id eventID, const Event *eventData, void* customData );
public ref class Library
{
public:
delegate void eventRegistered(const event_id eventID);
internal:
eventRegistered ^_event_registered;
private:
gcroot<Library^> *_native_handle;
public:
Library();
~Library();
error_status registerEvent(eventRegistered ^evento);
};
}
file wrapper.cpp:
#include "stdafx.h"
#include "wrapper.h"
namespace Pixium {
Library::Library()
{
_native_handle = new gcroot<Library^>();
_event_registered=nullptr;
}
Library::~Library()
{
delete _native_handle;
}
error_status Library::registerEvent(eventRegistered ^evento)
{
_event_registered=evento;
return TED_PixRad_RegisterEventCallback(cdeclEventCallback,_native_handle);
}
void cdeclEventCallback(const event_id eventID, const Event *eventData, void* customData )
{
gcroot<Library^> & native_handle = *((gcroot<Library^>*)customData);
native_handle->_event_registered(eventID);
}
}
In an application class I try to use this wrapper to receive the values event returned.
In particular in the constructor I initialize the wrapper object:
Form1(void)
{
InitializeComponent();
this->lib=gcnew Library(); //istanzio il wrapper
//event_registered= gcnew Library::eventRegistered(this,&Form1::processEvent);
this->registerEvent();
}
and in the function I call a wrapper event register funciotn:
void Form1::registerEvent()
{
//error_status err_reg_event=TED_PixRad_RegisterEventCallback((eventCallback_t)Marshal::GetFunctionPointerForDelegate(del).ToPointer(),_native_handle);
error_status err_reg_event=this->lib->registerEvent(); //utilizzo il wrapper
if (this->TestError(err_reg_event)){
this->button2->Visible=true;
}
}
The problem: I think a mistake to use the wrapper by my application or also in wrapper building.
Infact I' ve got error on the callback function when I try to receive event message.
I apologize for my bad English, hoping to be able to explain problem
Someone can indicates me an example or tutorial to learn how can I work with managed C++/CLI and unmanaged C type?
Thanks
|
|
|
|
|
|
Hi John,
thanks to help me.
I followed your advice and I've read How to: "Marshal Callbacks and Delegates Using C++ Interop"
I've tried to work on my application.
I' ve done this:
1) I decided to create a simple example without wrapper.h. So I' working only in a Form1.h.
2) Since my form1.exe work with the library of an electronic device and I constantly receive
the events returned by this device, I thinked to put the define of delegate, IntPtr and the callback unmanaged function as form1 private attributes and I declared them in the Form1 constructor:
Form1(void)
{
InitializeComponent();
_native_handle=new gcroot<Form1^>();
evento=gcnew eventRegistered(cdeclEventCallback);
gch =GCHandle::Alloc(evento);
ip=Marshal::GetFunctionPointerForDelegate(evento);
cb=static_cast<eventCallback_t>(ip.ToPointer());
GC::Collect();
this->registerEvent();
}
3) After, in constructor, I call the function registerEvent(). In this function I put the calling at the library function "TED_PixRad_RegisterEventCallback":
void Form1::registerEvent()
{
error_status er_return=TED_PixRad_RegisterEventCallback(cb,_native_handle);
if (this->TestError(er_return)){
this->button2->Visible=true;
}
}
4) the callback implementation in my Form1 is this:
void cdeclEventCallback(const event_id eventID, const Event *eventData, void* customData )
{
gcroot<Form1^> & native_handle = *((gcroot<Form1^>*)customData);
native_handle->processEvent(eventID,"evento");
}
Oss1: I think I must using _native_handle and not passing this (Form1 refer).
Oss3: processEvent is an internal function of Form1 that receive the code eventID and write the code mean in a form1 label.
Oss2: The compilation is without errors or warnings.
Assuming that I can not debug because the device connected to a machine other than the development,I have seen that the device gives me error event handling return
In particular, writing message on Form1 labels I' ve seen that I cannot enter in cdeclEventCallback function and I cannot call processEvent().
I can not understand what could be in error and this is a logic error in using Marshal:: GetFunctionPointerForDelegate in my example.
Have you got any advice for me?
Thanks for the help
|
|
|
|
|
OSS1:
I find that probably the error lies in the way the gcroot, because if I pass NULL in place of _native_handle and put processEvent () outside of Form1, I do not come back errors on callback events in the logs of the device;
OSS2: I used gcroot to pass ref of FORM1 between the managed and unmanaged code;
OSS3: I remember that the prototype of "TED_PixRad_RegisterEventCallback" library function is:
error_status TED_PixRad_RegisterEventCallback( eventCallback_t eventCallbackProc,
void* customData = NULL )
and the protorype of callback function by unmanaged library to my managed applicaiton is:
typedef void (*eventCallback_t)( const event_id eventID, const Event *eventData,
void* customData );
and customData for me is my Form1 (in general my object class).
PROBLEM:
I must implements processEvent like object function (then as Form1 funciotn) and so I must to pass FORM1 refer in TED_PixRad_RegisteredEventCallback that is the function of unmanaged library.
Any ideas?
|
|
|
|
|
I've never done this with C++/CLI but I've done it quire frequently between C# (managed) and C (native), and the one thing to remember is in the native world you must declare the callback function as StdCall.
You can read some about C#-C in this article of mine[^].
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi luc,
thantks for advice.
Reading your article, I had an idea:
- I haven't used gcroot but directly GCHandle.
- I must casting because parameter library function is void*.
This is what I've done:
1) I 've used GCHandle to build an handle to object (for my example FORM1) and I've used GCHandle.Alloc() to reserve memory when i send object refer from managed code to unmanaged library. I' ve done this in the constructor. So it is:
Form1(void)
{
InitializeComponent();
evento=gcnew eventRegistered(Form1::cdeclEventCallback);
gch =GCHandle::Alloc(evento);
ip=Marshal::GetFunctionPointerForDelegate(evento);
cb=static_cast<eventCallback_t>(ip.ToPointer());
GC::Collect();
gch3=GCHandle::Alloc(this);
this->registerEvent();
}
2) I've used GCHandle::ToIntPtr to obtain pointer of handle to send like parameter.I've done this in my registerEvent() function when i call library funciton. registerEvent() now is:
void Form1::registerEvent()
{
error_status er_return=TED_PixRad_RegisterEventCallback(cb,(void*)(GCHandle::ToIntPtr(gch3)));
if (this->TestError(er_return)){
this->button2->Visible=true;
}
}
3) Since library function receives void* customData parameter and it returns this in callback function, I must cast my pointer Form1 refer from IntPtr to void*. After, in the callback function I must casting from void* to IntPtr and in second time I must casting from intPtr to Form1^.
The implementation of the callback funciton now is:
static void Form1::cdeclEventCallback(const event_id eventID, const Event *eventData, void* customData )
{
GCHandle gch4 = GCHandle::FromIntPtr((IntPtr)(customData));
Form1^ frm = (Form1^)gch4.Target;
frm->label3->Text="GESTIONE EVENTO";
frm->label3->Refresh();
frm->processEvent(eventID,"");
}
Now I must call processEvent like an object function and not like Form1 external function.
---------------------------------------------------------------
I compiled without problems and doing some tests I've seen that behavior is correct, that the occurrence of an event correctly calls the callback function and that this uses the correctly reference at Form1.
Less than denials I think the problem is solved, thank you all for your help.

|
|
|
|
|