|
Since this is the C++/CLI forum, I'll give you a Managed reply -- use the TryParse static method on Int32 and/or Double classes.
int val;
String^ s = "10.22";
if (System::Int32::TryParse(s,val))
else
John
modified 17-Jul-12 10:24am.
|
|
|
|
|
Thanks John for your reply. I am sorry I posted this thread in C++/CLI forum. Actually I was looking for a solution in C++/MFC.
Sorry for the inconvinience.
Cheers,
Abinash
|
|
|
|
|
Read char by char in a file after write char by char to another file in vc++.
Can any one reply me.
Thanks,
lucky.
|
|
|
|
|
|
I need to pass a managed callback to an unmanaged TCP receiver. Since its a thread that needs to exist for the lifetime of the application, I need to prevent it from getting garbage collected. I have read everywhere that pinning function pointers is not required and the GCHandle.Alloc will do the job of preventing garbage collection.
But is this a given? I have seen that the AppPool hosting this code crashes with an access violation. Why should I not suspect the fact that this error occurs because the function pointer was garbage collected?
Why does pinning the pointer as below reduce the number of crashes?
typedef void (__cdecl *ProcMessageFunc)(void* param, void* paramBuf, ULONG bufSize);
FuncDelegate^ fp = gcnew MessageFuncDelegate(this, &Handler);
pin_ptr<MessageFuncDelegate^> pinnedFunctionPointer = &fp;
ret = Receiver ((ProcMessageFunc)pinnedFunctionPointer);
|
|
|
|
|
Difficult to say from what you have shown. You can pin a handle to a managed object only temporarily, since a pin_ptr can only be created on the stack. Therefore, if you have something like this:
IntPtr YourClass::GetFuncPointer()
{
FuncDelegate^ fp = gcnew MessageFuncDelegate(this, &Handler);
pin_ptr<MessageFuncDelegate^> pinnedFunctionPointer = &fp;
return ((ProcMessageFunc)pinnedFunctionPointer);
}
then you effectively have only pinned fp for the duration of this method call. A correct way to do this depends on your scenario. I'd recommend something along the lines of the following (I didn't compile it, but you get the idea):
public ref class ClientRegistrar abstract sealed {
static FuncDelegate^ s_ManagedReceiverList;
public static void RegisterClient(YourClient^ p_Client)
{
s_ManagedReceiverList +=
gcnew MessageFuncDelegate(p_Client, &YourClient::Handler);
::Receiever((ProcMessageFunc)Marshal::GetFunctionPointerForDelegate(s_ManagedReceiver));
}
public static void UnregisterClient(YourClient^ p_Client)
{
s_ManagedReceiverList -=
gcnew MessageFuncDelegate(p_Client, &YourClient::Handler);
}
}
Usage (C#):
YourClient tClient = new YourClient();
ClientRegistrar.RegisterClient(tClient);
s_ManagedReceiverList and any YourClient instance you register via RegisterClient will be kept alive as long as the current application domain will exist. Implement UnregisterClient if you need more fine grained control. A delegate does not need to be pinned, the CLR takes care of proper handling of that. It just needs to be kept alive.
Cheers,
Paul
modified 17-Jul-12 10:14am.
|
|
|
|
|
Hi, there
Please give me vc++ learn pdf document or web address or explain about make and use resource dialogbox in vc++
thank you so much
|
|
|
|
|
See here[^] for DIALOGEX resource statements, and here[^] for programming guides.
|
|
|
|
|
Please Leave A Sample Source code project if possible with description I'm new comer for VC++
Thank you for your reply
|
|
|
|
|
Sorry but you will have to find your own. If you are using Visual Studio or Visual C++ Express[^] to create your projects you can use the template in the new project wizard to generate a Dialog project and work from there. You can also find lots of samples in the Articles[^] section.
|
|
|
|
|
Hi, Iam using VC++ 2010. While I want to get the MdiParent-Forms Instance, its giving the error, Really I can't identify my mistake...
My Codes from MdiParent
=======================
#include "For_Student_Detials"
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
For_Student_Detials^ MyStudentDet= For_Student_Detials::GetForm(true,this);
MyStudentDet->MdiParent=this;
MyStudentDet->FormBorderStyle=System::Windows::Forms::FormBorderStyle::None;
MyStudentDet->Dock=DockStyle::Fill;
MyStudentDet->Show();
}
My Codes From MdiChild // CFIS_Main is my Mdi-Container
=========================================================
#any Include Reqd?????
public: static For_Student_Details^ For_Student_Details::_instance = nullptr;
public: static For_Student_Details^ For_Student_Details::GetForm(bool^ IsMDIChild, CFIS_Main^ MyInstFrm) {
if (_instance == nullptr)
_instance = gcnew For_Student_Details();
if (_instance->IsDisposed)
_instance = gcnew For_Student_Details();
if (IsMDIChild)
_instance->MdiParent = MyInstFrm;
return _instance;
}
From the above code I can't identify my mistake, Does anybody can point me?
Thanks For Helps
|
|
|
|
|
Paramu1973 wrote: While I want to get the MdiParent-Forms Instance, its giving the error
What error?
|
|
|
|
|
Thanks Richard...Thanks for the helps...
Error()
error C2061: syntax error : identifier 'CFIS_Main'
error C2065: 'MyInstFrm' : undeclared identifier
error C2660: 'MyProjectName::For_Student_Details::GetForm' : function does not take 2 arguments
modified 12-Jun-12 8:54am.
|
|
|
|
|
And you expect us to guess how this relates to your project? Please collect information properly, and show the actual lines of code and messages together, ensuring that you identify which line of code is marked with which error.
You could also look more closely at these messages and work out for yourself:
- why the identifier '
CFIS_Main ' is not recognised. - why you are using the variable '
MyInstFrm ', when it has not been defined in the current compilation unit. - why the call to '
MyProjectName::For_Student_Details::GetForm() ' has the wrong number of arguments.
|
|
|
|
|
Thanks Richard...Manythings I learned from you...
Still all are in mind....I won't forget you & Dave, etc..etc...
Thanks Again
|
|
|
|
|
How to convert from 'WCHAR' to 'System::String ^' Managed C++
|
|
|
|
|
Use one of the constructors as described here[^].
|
|
|
|
|
int x = (Int32) thisisObjectType is boxing, if the type is already checked ?
if (thisisObjectType->GetType() == Int32::typeid) {
int x = (Int32) thisisObjectType; }
|
|
|
|
|
Why would you use TryParse() if it's already an integer, and why would you need a cast?
|
|
|
|
|
Hi,
From many places Iam still searching to find a solution but not yet clear to me..Its hunting my head...I will be happy, does anybody gives a solution to me..
Actually Iam having VS2010 Ultimate... on 2 systems. I updated 1 system to SP1 &
Windows 3.0 API. That system is 1ly giving the error like...
The Method or Property VCFilter::get_UrlBehavior deprecated and nolonger implemented....
But in another system, without update, still its working fine...
when I create XML_Schema, DataSet by XML Codes, and I can access that DataSet in reports dataset tab... earlier it has worked for me...
Now its giving this error, while I try to access that from Report Data Menu,DataSet Tab...
And therefore I get confused for the above problem....Any right directions for me...
Thanks again...
modified 7-Jun-12 6:15am.
|
|
|
|
|
I just read on stackoverflow[^] that it is probably possible to use C++ CX in normal desktop app (NOT a WinRT app).
(To replace Managed C++ / C++ CLI, with better performance and simplicity)
I wonder, is there any article / blog describing the process? and some fun application of it??
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Hi,
i cannot figure out if static typing and strong typing are the same thing.
Please advise.
Thanks
|
|
|
|
|
They are pretty much the same to a degree.
""Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I can only hope that answers the question to some degree, although I might not be quite sure.
|
|
|
|
|
I know, I was pretty vague
""Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|