|
The first line creates a String^. I believe you already have that in textBox->Text.
The second line converts that to a string.
The third line converts that to a wstring.
What else do you not see?
|
|
|
|
|
I guess I need the second then.
Currently I have
std::string str1 = (const char*)(Marshel::StringToHGlobalAnsi(textBox->Text)).ToPointer();
But it gives me the following errors:
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2653: 'Marshel' : is not a class or namespace name
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2228: left of '.ToPointer' must have class/struct/union
1> type is ''unknown-type''
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C3861: 'StringToHGlobalAnsi': identifier not found
So I tried to #include <marshal>, but that didn't work either.
How can I use this function?
And by the way - thanks for your fast replies 
|
|
|
|
|
Typo
It should be Marshal .
You got it wrong there.
Look at my posting.
|
|
|
|
|
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(7) : fatal error C1083: Cannot open include file: 'Marshal': No such file or directory
:p Yeh - I corrected it but copied the wrong stuff I saw...
But with A its still not working
I am using Visual C++ Express Edition. Downloaded the package yesterday :p
|
|
|
|
|
I suspect some mix-up in your code.
You do not have to include any file called Marshal .
And you can use this class only in managed applications.
|
|
|
|
|

#pragma once
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
namespace TerminalApp {
using namespace std;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
std::vector<string> textCode;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ exitButton;
private: System::Windows::Forms::Button^ addText;
private: System::Windows::Forms::RichTextBox^ textBox;
private: System::Windows::Forms::Button^ saveButton;
private: System::Windows::Forms::TextBox^ invoerVeld;
private: System::Windows::Forms::Button^ voegTextButton;
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->exitButton = (gcnew System::Windows::Forms::Button());
this->addText = (gcnew System::Windows::Forms::Button());
this->textBox = (gcnew System::Windows::Forms::RichTextBox());
this->saveButton = (gcnew System::Windows::Forms::Button());
this->invoerVeld = (gcnew System::Windows::Forms::TextBox());
this->voegTextButton = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
this->exitButton->Location = System::Drawing::Point(645, 269);
this->exitButton->Name = L"exitButton";
this->exitButton->Size = System::Drawing::Size(85, 35);
this->exitButton->TabIndex = 0;
this->exitButton->Text = L"Exit";
this->exitButton->UseVisualStyleBackColor = true;
this->exitButton->Click += gcnew System::EventHandler(this, &Form1::exitApp);
this->addText->Location = System::Drawing::Point(16, 24);
this->addText->Name = L"addText";
this->addText->Size = System::Drawing::Size(85, 35);
this->addText->TabIndex = 1;
this->addText->Text = L"AddText";
this->addText->UseVisualStyleBackColor = true;
this->addText->Click += gcnew System::EventHandler(this, &Form1::addText_Click);
this->textBox->Location = System::Drawing::Point(337, 24);
this->textBox->Name = L"textBox";
this->textBox->ReadOnly = true;
this->textBox->ScrollBars = System::Windows::Forms::RichTextBoxScrollBars::None;
this->textBox->Size = System::Drawing::Size(393, 239);
this->textBox->TabIndex = 2;
this->textBox->Text = L"";
this->saveButton->Location = System::Drawing::Point(554, 269);
this->saveButton->Name = L"saveButton";
this->saveButton->Size = System::Drawing::Size(85, 35);
this->saveButton->TabIndex = 3;
this->saveButton->Text = L"Save";
this->saveButton->UseVisualStyleBackColor = true;
this->saveButton->Click += gcnew System::EventHandler(this, &Form1::saveButton_Click);
this->invoerVeld->Location = System::Drawing::Point(16, 269);
this->invoerVeld->Name = L"invoerVeld";
this->invoerVeld->Size = System::Drawing::Size(130, 20);
this->invoerVeld->TabIndex = 4;
this->voegTextButton->Location = System::Drawing::Point(178, 269);
this->voegTextButton->Name = L"voegTextButton";
this->voegTextButton->Size = System::Drawing::Size(70, 34);
this->voegTextButton->TabIndex = 5;
this->voegTextButton->Text = L"VoegToe";
this->voegTextButton->UseVisualStyleBackColor = true;
this->voegTextButton->Click += gcnew System::EventHandler(this, &Form1::voegTextButton_Click);
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(742, 316);
this->Controls->Add(this->voegTextButton);
this->Controls->Add(this->invoerVeld);
this->Controls->Add(this->saveButton);
this->Controls->Add(this->textBox);
this->Controls->Add(this->addText);
this->Controls->Add(this->exitButton);
this->MaximizeBox = false;
this->MaximumSize = System::Drawing::Size(750, 350);
this->MinimumSize = System::Drawing::Size(750, 350);
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"Applicatie";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void exitApp(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
private: System::Void addText_Click(System::Object^ sender, System::EventArgs^ e) {
String^ tmp = textBox->Text;
textBox->Text = "\r\n" + tmp + "Blah";
}
private: System::Void saveButton_Click(System::Object^ sender, System::EventArgs^ e) {
fstream fout("c:/ostream.txt", std::ios_base::app);
textCode.push_back("1");
textCode.push_back("2");
textCode.push_back("3");
textCode.push_back("4");
textCode.push_back("5");
fout.close();
}
private: System::Void writeToTextbox(void) {
}
private: System::Void voegTextButton_Click(System::Object^ sender, System::EventArgs^ e) {
textBox->Text += invoerVeld->Text + "\r\n";
invoerVeld->Text = "";
invoerVeld->Focus();
writeToTextbox();
std::string str1 = (const char*)(Marshel::StringToHGlobalAnsi(textBox->Text)).ToPointer();
}
};
}
That's the code I have at the moment. Im trying to make a Forms Application - Im quite new to Forms Applications and only have made console apps before... :p
|
|
|
|
|
Try adding this line -
using namespace System::Runtime::InteropServices;
|
|
|
|
|
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2653: 'Marshel' : is not a class or namespace name
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2228: left of '.ToPointer' must have class/struct/union
1> type is ''unknown-type''
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C3861: 'StringToHGlobalAnsi': identifier not found
Is there any other known way to get text out such TextBox into a string? One made by Microsoft themselves? :p
|
|
|
|
|
You have typed in Marshel .
The correct spelling is Marshal .
Do you see the difference?
|
|
|
|
|
How strange - because I copied it directly from your post - since first of all I hate typing and secondly its always better to copy paste :p
But it is working now - let me test the output etc.
Thanks in advance <3
|
|
|
|
|
But I really think you should not be driving now.
|
|
|
|
|
No Im not driving lol.
It works!
*cheering the hell outta it*
Adding text to the TextBox and with a button its sending the data to my vector string which can be read and send to the output
Thank you very very much! I really needed this line!
<33 ![Rose | [Rose]](https://codeproject.global.ssl.fastly.net/script/Forums/Images/rose.gif)
|
|
|
|
|
Hi there,
I got the following problem. For an application that I have already up and running I wrote something like an observer program. The observer simply checks from time to time if the application is still alive and responding. If that is, for whatever reason, no the case, the observer kills the application process (TerminateProcess()) and starts another instance.
Now that works quite well so far. Only when a windows error report or such something pops up in the trail of an application crash, the observer is unable to kill the application. So the whole mechanism breaks down.
My question is, is there a possibility to kill an application nonetheless? Or to find out what is blocking the killing and to kill that one first then?
I could get all the possible process names of the processes that might show up, but that will always leave a hole in the system.
Any ideas on that?
Souldrift
|
|
|
|
|
Souldrift wrote: My question is, is there a possibility to kill an application nonetheless?
I would have thought TerminateProcess() to be the right choice as it is used to unconditionally cause a process to exit.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
First and foremost: never use TerminateProcess to terminate your application, there should be a better method.
If you nonetheless want, at extreme stage, to kill unconditionally the application then use TerminateProcess (rules are there to be broken... ): as suggested by David, there's no worst hammer than such a function (AFAIK).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Check the return value of TerminateProcess() and get the error code, if any, using GetLastError() .
Is the application and observer running in different user contexts?
If so GetLastError should return Access Denied(5) .
|
|
|
|
|
Hey, I'm using Windows Hook, I installed the mouse hook, system-wide and its working perfectly. Now there is a problem, I need to the get window handle on which the mouse was clicked.. How do I do that? Does the Mouse hook event passes us that information?
|
|
|
|
|
Are you using WH_MOUSE ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Well, I was using WH_MOUSE_LL earlier. I changed my code to WH_MOUSE.
Now the code is:
HWND hWnd = NULL;
HWND hDesktopListWnd = NULL;
hWnd = FindWindow(_T("ProgMan"), NULL);
hWnd = GetWindow(hWnd, GW_CHILD);
hDesktopListWnd = GetWindow(hWnd, GW_CHILD);
threadID = GetWindowThreadProcessId(hDesktopListWnd, NULL);
hookMouse = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)InternalMouseHookCallback, g_appInstance, threadID);
It installs the hook successfully, but I don't get the mouse hook events now. Basically I want to get click events when any icon on the desktop is clicked.
|
|
|
|
|
Ahmed Manzoor wrote: Well, I was using WH_MOUSE_LL earlier.
In the LowLevelMouseProc() function, the lParam is a MSLLHOOKSTRUCT structure.
Ahmed Manzoor wrote: I changed my code to WH_MOUSE.
In the MouseProc() function, lParam is a MOUSEHOOKSTRUCT structure.
Both of these structures have a pt member.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hmmm. But I ran into another problem. Since I only needed Desktop's ListView (SysListView32) mouse events. I used WH_MOUSE because it can be thread specific whereas WH_MOUSE_LL can be global hook only that's why.
Now when I did this change, I'm not getting any events when I click on the desktop icons or anywhere in the desktop.
hookMouse = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)InternalMouseHookCallback, g_appInstance, threadID);
Here g_appInstance is the address of the DLL. threadID is the ID of the thread in which there is the SysListView32 (which is the desktop). InternalMouseHookCallback is a callback of .NET function.
But now its not working. Please help me out. I'm using the Global System Hooks in .NET
|
|
|
|
|
The first parameter is wrong.
hookMouse = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)InternalMouseHookCallback, g_appInstance, threadID);
You should handle "WM_MOUSE" in the "InternalMouseHookCallback".
|
|
|
|
|
|
transoft wrote: The first parameter is wrong.
No, WH_MOUSE is correct.
transoft wrote: You should handle "WM_MOUSE" in the "InternalMouseHookCallback".
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I am writing a C++ application using Win32 API (i.e. no MFC, no .NET). I want to process some major messages such as WM_PAINT, WM_MOUSEMOVE, and WM_CHAR in the dialog procedure (let's call it DialogProc). The dialog is created using DialogBox or DialogBoxIndirect in some cases, and DialogProc is passed as the fourth argument to DialogBox. My problem is these aforementioned messages (WM_PAINT etc.) are not passed to DialogProc. Is there any way to catch and handle these messages in a dialog box procedure? or do I have to create a dialog box using RegisterClass and CreateWindow? I appreciate your help.
|
|
|
|