|
I have developed an application(managed + unmanaged) in VC++ using Visual Studio 2005. It can switch to either Console or to windows form depending upon the no of parameters passed to the application on command prompt console. Its basically a windows application but console has been implemented with the help of Attachconsole(), allocconsole() & freeconsole().
Now if i run a batch file, using command prompt console, all the output messages of the application can be seen on the console as shown below.
c:\test> testapp -f filename -l operationname -t otherparams
filename selected..
operation in progress..
operation completed successfully!!
But if i redirect the output of the console to a text file, i dont see any messages in the text file once the operation is complete.
for eg:
c:\test> testapp -f filename -l operationname -t otherparams >> logfile.txt
Clarifications i need are
1. am i missing something to log it in a text file?
2. Can output messages from the console be logged in such a fashion. if yes, how?
Thanks in advance for help/suggestions on the same.
|
|
|
|
|
This looks correct to me. What happens when you type a simple command (e.g. dir ) instead of your application command line?
|
|
|
|
|
If i type in "Dir" command, normal dir contents are displayed.
you mean to say the console that is opened in my application is not a standard console to redirect the output/input using ">>" or ">"? If yes, then how do i redirect teh input & output to a file?
Thanks
|
|
|
|
|
santoshkaif wrote: you mean to say the console that is opened in my application is not a standard console to redirect the output/input using ">>" or ">"? If yes, then how do i redirect teh input & output to a file?
I'm not sure I understand what you are saying here. If you run an application in a command window then you should be able to redirect the output to a file. Are you saying that you are doing something different?
|
|
|
|
|
Hello,
I need some help with the following:
I created a form with textfields there are 2 buttons on the form to save or to cancel.
I also added a leave event on some text fields because I need a test to control if the field is filled in.
When I'm on a field that needs to be filled and I push the cancel button without putting some value in the field the leave event still is executed then I get the message that field has to be filled in!
How can I solve this? How can I test if the cancel button is pushed in the leave of that text field?
Thanks for the help!
|
|
|
|
|
why do you want to validate inputs on Control.Leave? just do it when the "Save" Button is pressed.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
I thought of that too but the save button closes also the form (Form is called from another form with a datagridview on it. This form is the contents of a record). And If I push the save button, I get the message but I cannot put focus back into the textfield because of the form that's closing?
Any other suggestion?
modified on Thursday, November 5, 2009 8:18 AM
|
|
|
|
|
The "Save" Button will do what you tell it to do, most likely "validate, and if OK, then close".
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
You're right but if I do that how does the main program (calling program) knows that buttonOK is pushed?
form2 is made with UI!
Form^ form2 = gcnew Form;
form2->buttonSave->DialogResult = ::DialogResult::OK;
form2->buttonCancel->DialogResult = ::DialogResult::CANCEL;
form2->ShowDialog();
if ( form2->DialogResult == ::DialogResult::OK )
{
...
DataAdapter->Update(myDataSet, "DATA");
}
modified on Thursday, November 5, 2009 8:26 AM
|
|
|
|
|
Hi,
IMO you should remove the form2->buttonSave->DialogResult = ::DialogResult::OK; line, and provide a real click handler for that button, wherein you
1) validate
2) if OK, set DialogResult::OK and close the dialog.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
This is my event for the save button
System::Void buttonSave_Click(System::Object^ sender, System::EventArgs^ e)
{
if (this->textBox1->Text == "")
{
MessageBox::Show("Field is obligated");
this->textBox1->Focus();
}
else
{
this->DialogResult == ::DialogResult::OK;
this->Close();
}
}
In main program it doesn't work! DialogResult is not OK
I probably do something wrong, any other suggestions?
|
|
|
|
|
Any other/further suggestions on this issue?
|
|
|
|
|
Hi all, this is my first post. Normally I am able to figure out the problems I encounter either by searching this board or others like it on the web but not this time. I've been fighting with this for weeks now and am finally turning to you guys. Any and all help is appreciated.
I've got a CORBA Event channel feeding multiple applications data. If you are unfamiliar with CORBA it's okay, you don't need to know much aside from that the code generated for CORBA related functions in UNMANAGED. The data is pushed at a 1Hz interval and the applications register as a consumer to receive the data. My task is to create a common DLL for all Managed applications that are being built going forward that makes the registering and consumption of data easy and localized.
I've had little problem getting this to work with primitive data types but the final piece of my puzzle is to receive a sequence of data that is in a CORBA defined structure.
Here is what I am dealing: a Managed C++ DLL (built with CLR support) that contains Managed and Unmanaged(CORBA) classes, and a C# Application that references the DLL.
The MDA (Managed Debugging Assistant) Gives this description:An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module.
Attempting to call into managed code without transitioning out first. Do not attempt to run managed code inside low-level native extensibility points, such as the vectored exception handler, since doing so can cause corruption and data loss.
After hitting continue I get an ExecutionEngineException:
An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module.
**The following code snippets are in the Managed C++ DLL**
ManagedWrapper.h
public delegate void BasicCallbackDelegate(short cmd);
public delegate void NonBasicCallbackDelegate(array<EPClass^>^ epList);
[StructLayoutAttribute(Sequential, CharSet = Ansi )]
public ref struct ManagedBasicDelegateWrapper
{
[MarshalAsAttribute(UnmanagedType::FunctionPtr)]
BasicCallbackDelegate^ _Delegate;
};
[StructLayoutAttribute(Sequential, CharSet = Ansi )]
public ref struct ManagedNonBasicDelegateWrapper
{
[MarshalAsAttribute(UnmanagedType::FunctionPtr)]
NonBasicCallbackDelegate^ _nDelegate;
};
public ref class ManagedWrapperClass
{
public:
ManagedWrapperClass(ManagedBasiceDelegateWrapper^ cbd);
ManagedWrapperClass(ManagedNonBasicDelegateWrapper^ cbd);
};
ManagedWrapper.cpp
extern class BasicPushConsumer *BasicPushConsumerObject;
extern class NonBasicPushConsumer *NonBasicPushConsumerObject;
ManagedWrapperClass::ManagedWrapperClass(ManagedBasicDelegateWrapper^ cbd)
{
gt_Callback callback;
Marshal::StructureToPtr(cbd, safe_cast<System::IntPtr>(&callback), false);
BasicPushConsumerObject->SetCallbackInUnmanaged(callback);
}
ManagedWrapperClass::ManagedWrapperClass(ManagedNonBasicDelegateWrapper^ cbd)
{
ep_Callback callback;
Marshal::StructureToPtr(cbd, safe_cast<System::IntPtr>(&callback), false);
NonBasicPushConsumer->SetCallbackInUnmanaged(callback);
}
*pruned* NonBasicPushConsumer.cpp
typedef void (*gt_Callback) (short cmd);
typedef void (*ep_Callback) (array<EPClass^>^ epList);
void NonBasicPushConsumer::SetCallbackInUnmanaged(ep_Callback ptr2f)
{
scallback = ptr2f;
}
void NonBasicPushConsumer::ManagedMethodToCall(array<EPClass^>^ epList)
{
scallback(epList);
}
**The following code is part of the C# Application**
*pruned* Form1.cs
ManagedNonBasicDelegateWrapper mcf = new ManagedNonBasicDelegateWrapper();
mcf._epDelegate = new EntityPositionCallbackDelegate(CallbackFunction);
ManagedWrapperClass mwc = new ManagedWrapperClass(mcf);
public static void CallbackFunction(System.Array epList)
{
Console.WriteLine("CALLBACK!");
}
modified on Wednesday, November 4, 2009 6:44 PM
|
|
|
|
|
'System.Array' is pretty useless - more often used for COM interop - try changing the C# declaration to use a 'proper' C# array:
public static void CallbackFunction(EPList[] epList)
David Anton
http://www.tangiblesoftwaresolutions.com
Convert VB to C#, C++, or Java
Convert C# to VB, C++, or Java
Convert C++ to C#, VB, or Java
Convert Java to C#, C++, or VB
|
|
|
|
|
Unfortunately this did not remedy the issue, I have the same error. Anyone have any other suggestions?
|
|
|
|
|
Hi Expert,
I want to run command from my application and get the returned result.
ex: in the cmd i put "set MyVariableName" the string return is value of the Environment Variable.
I want to do it from my code and i want the returned value.
Is it possible or not and How?
Thanks.
|
|
|
|
|
Hi,
Am deleoping application using VC++ on VS2005. My application needs to switch to console application if the commandline parameters are mentioned on the command prompt console else to windows form dialog. for eg:
test.exe --help
on command prompt should display on command console(black backgrnd console window) and if cmd is
test.exe
window form should be opened.
This has been accomplished by creating the project of the type window form and then project properties->system->subsystem to Console (/SUBSYSTEM:CONSOLE)
But now the issue what i am facing are
1> when window form is opened with ex cmd test.exe, black color console window is also opened.
2> when console is closed, window form also closes
solutions i need correspondingly are
1> how to hide/close the console window when windows form is open?
2> can the Can console and window form controls be made independent? if yes how?
Searched and tried lots of solutions provided over net, but of less help.
Help on this will be appreciated.
Thanks,
Santosh
|
|
|
|
|
There is no way to hide the console programically.
A dirty way to achieve what you need is: Create two executables. First executable will be console and second will be windows. Second executable is your applications executable. Always invoke the first executable and if its is invoked using command line parameters, write the necessary details to the console. If no command line parameters are specified, start your main exe and exit this one.
Let me know if you find a better approach.
Best wishes,
Navaneeth
|
|
|
|
|
Agree but I need to deliver a single exe.
|
|
|
|
|
[DllImport("Kernel32.dll")]
extern int AllocConsole();
[DllImport("Kernel32.dll")]
extern int FreeConsole();
[DllImport("Kernel32.dll")]
extern int AttachConsole(UInt32 dwProcessId);
...
AllocConsole();
Console::WriteLine("Write to the console!");
...
FreeConsole();
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Great. Good to learn new things every day.
Best wishes,
Navaneeth
|
|
|
|
|
Hi,
My VC++ application(managed code) uses unmanaged code library(.lib) and am using VS2005.
During deployment, I also need to send few more dlls along with the exe. I just want all the modules (external dlls to be deployed and the exe) into a single exe.
I tried using ILMerge, but when i run the merged exe it throws up exception as "bad unmanaged code entrypoint". But if i try the same with pure managed code(without any unmanaged lib included), then the merged exe runs fine.
I also tried Netz. Could not successfully run with this too. Pure managed code runs fine here too.
So, clarification i need is whether the exe generated from a code(which has both managed and unmanaged code) can be merged with dlls? if yes, pls let me know the steps too.
Thanks in advance
-Santosh
|
|
|
|
|
Can't you statically link those libraries rather than providing DLL's?
Best wishes,
Navaneeth
|
|
|
|
|
Those DLL's are microsoft provided. I just want to avoid deploying msvc**.dll files.
Am amateur in application programming. So want to know Can DLL's be statically linked? if so how?
|
|
|
|