incompatible with parameter of type "LPCTSTR" - c++-cli

So i got this error:
argument of type System::String ^ is incompatible with parameter of
type LPCTSTR
When i try to use this code:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
String^ currentDesktop = System::Environment::GetEnvironmentVariable("USERPROFILE") + "\\Desktop\\Test";
CreateDirectory (currentDesktop, NULL);
String^ value = (this->listBox1)->Text;
MessageBox::Show ("File has been created successfully. You've choosen: " + value, "Success", MessageBoxButtons::OK, MessageBoxIcon::Information);
}
};
So i don't know exactly where is the problem, So help me please.

Thank you guys, and thank you #Ben Voigt
This code working fine:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
String^ currentDesktop = System::Environment::GetEnvironmentVariable("USERPROFILE") + "\\Desktop\\Test";
msclr::interop::marshal_context context;
LPCTSTR desktop = context.marshal_as<LPCTSTR>(currentDesktop);
CreateDirectory (desktop, NULL);
String^ value = (this->listBox1)->Text;
MessageBox::Show ("File has been created successfully. You've choosen: " + value, "Success", MessageBoxButtons::OK, MessageBoxIcon::Information);
}
};

Related

How to use variable in another windows form?

How to use variable in another windows form? For example:
This is Form 1 event button click. After clicking th button i want to apear "num"
in textbox "Form2" form.
private: System::Void button_Click(System::Object^ sender, System::EventArgs^ e)
{
int num = 10;
Form2^ f = gcnew Form2();
f->Show();
}
lets suppose that in form2 is textbox named "text"
private: System::Void Form2_Load(System::Object^ sender, System::EventArgs^ e)
{
text->Text = num;
}
Form2 doesnt see "num" variable.
Im using c++/CLI (visual studio)
Try this instead:
private: System::Void button_Click(System::Object^ sender, System::EventArgs^ e)
{
int num = 10;
Form2^ f = gcnew Form2();
f->text->Text = num.ToString();
f->Show();
}

How to add event listener?

simple code:
((WebKit.DOM.EventTarget) img).add_event_listener_with_closure ("click", on_enter, false);
void on_enter() {
}
valac error:
error: Argument 2: Cannot convert from `on_enter' to `GLib.Closure'
Here is the full code example:
private void on_click(WebKit.DOM.EventTarget target, WebKit.DOM.Event event)
{
try
{
//var image = (WebKit.DOM.HTMLImageElement)target;
//image.set_attribute("class", "clickable-img-hover");
}
catch(GLib.Error e)
{
}
}
public static void webkit_web_extension_initialize (WebKit.WebExtension web_extension)
{
string PROG = "[webkit2_webextension_minimal_so.so] ";
print(PROG + "PLUGIN activated\n");
web_extension.page_created.connect((extension, web_page)=> {
print(PROG + "SIGNAL: page_created\n");
try {
var dom = web_page.get_dom_document();
WebKit.DOM.Element img = dom.create_element("img");
img.set_attribute("src", "file:///home/o/avatar.png");
img.set_attribute("alt", "avatar-1.jpg");
((WebKit.DOM.EventTarget) img).add_event_listener_with_closure("click", on_click, false);
dom.body.insert_before(img, null);
} catch (FileError e) {
stdout.printf ("Message: \"%s\"\n", e.message);
stdout.printf ("Error code: FileError.EXIST = %d\n", e.code);
stdout.printf ("FileErrors identification: %" + uint32.FORMAT + "\n", e.domain);
}
web_page.send_request.connect((request)=> {
if(request.uri.has_prefix("http://www.google") || request.uri.has_prefix("data")){
print(PROG + "SIGNAL: send request [REJECTED] " + request.uri + "\n");
return true; // true => block query
}
print(PROG + "SIGNAL: send request " + request.uri + "\n");
return false;
});
return;
});
}
Compile with:
valac --pkg glib-2.0 --pkg webkit2gtk-web-extension-4.0 --library=webext webext.vala -H webext.h -X -fPIC -X -shared -o webext.so
How to add event listener?
PS: This is a follow up question to this earlier question.
Looking at the documentation for the method:
public bool add_event_listener_with_closure (
string event_name,
owned EventTargetFunc handler,
bool use_capture
)
The second argument is owned EventTargetFunc handler.
So looking at the documentation of the delegate type:
public delegate void EventTargetFunc (EventTarget target, Event event)
Your method does not have this delgate type.
So you probably have to fix your method signature to something like:
void on_enter (EventTarget target, Event event) {
}

Writing and saving text into a file c++ visual studio

So here's this code :
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
mn=textBox1->Text;
MessageBox::Show(mn+" "+tsk, "Info" );
String^ fileName = "records.txt";
StreamWriter^ sw = gcnew StreamWriter("records.txt");
sw->Write(mn,tsk);
sw->Close();
}
Everytime I try to write something new into the file from the program, it just writes the new text and doesn't keep old. How can I save it, so it doesn't delete ?
The documentation for StreamWriter constructor states that you must set the append parameter to true to avoid a mere overwrite of the file. Your code should be:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
mn=textBox1->Text;
MessageBox::Show(mn+" "+tsk, "Info" );
String^ fileName = "records.txt";
StreamWriter^ sw = gcnew StreamWriter("records.txt", true); //append to file
sw->Write(mn,tsk);
sw->Close();
}

NullReferenceException was unhandledby user code

I am making a registration page and while using an input tag to upload image of the user, it is giving an error while running the website: "NullReferenceException was unhandledby user code". Please help me to sort this out. The method which is giving error is:
protected void Button2_Click(object sender, EventArgs e)
{
var path = "Memberimg";
string fn = System.IO.Path.GetFileName(f1.PostedFile.FileName);
string SaveLocation = Server.MapPath("Memberimg") + "\\" + fn;
if ((f1.PostedFile != null) && (f1.PostedFile.ContentLength > 0))
{
try
{
f1.PostedFile.SaveAs(SaveLocation);
Response.Write("The file has been uploaded.");
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
}
else
{
Response.Write("Please select a file to upload.");
}
}
You are referring to f1.PostedFile before checking to see if it is null, in the line with:
string fn = System.IO.Path.GetFileName(f1.PostedFile.FileName);

DOTMsn is not firing the SingedIn event

I have just started building a app using “XihSolutions.DotMSN.dll” version: 2.0.0.40909,
My problem is that it is not firing the “Nameserver_SignedIn” event. Not sure if I am doing something wrong.
your help will be really helpful.
void Nameserver_SignedIn(object sender, EventArgs e)
{
throw new Exception("User Signed In");
}
private string message = string.Empty;
void NameserverProcessor_ConnectionEstablished(object sender, EventArgs e)
{
message = "Connected";
SetMessage();
}
void SetMessage()
{
if (tbMessage.InvokeRequired)
tbMessage. Invoke(new ThreadStart(SetMessage));
else
tbMessage.Text += Environment.NewLine+ message;
}
private void btnSingIn_Click(object sender, EventArgs e)
{
if (messenger.Connected)
{
// SetStatus("Disconnecting from server");
messenger.Disconnect();
}
// set the credentials, this is ofcourse something every DotMSN program will need to
// implement.
messenger.Credentials.Account = tbUserName.Text;
messenger.Credentials.Password = tbPwd.Text;
// inform the user what is happening and try to connecto to the messenger network.
//SetStatus("Connecting to server");
messenger.Connect();
}
You might use MSNPSharp instead - DotMSN is old and may not support the current MSN protocol. There link is here:
http://code.google.com/p/msnp-sharp/