Visual C++ Help!

Something is wrong with my form

Page 1 of 1

1 Replies - 2060 Views - Last Post: 26 March 2010 - 01:36 AM

#1 m0v0nage  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-March 10

Visual C++ Help!

Posted 25 March 2010 - 07:03 PM

So I am using the ShellExecute() function and it worked fine in a console application, but not in a form. I understand that it has to do with the difference between Native and Managed C++. How do I fix it?


#include <windows.h>
#include <shlobj.h>

#pragma once


namespace FormTest {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected: 

private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentRe… resources = (gcnew System::ComponentModel::ComponentResourc…
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
// 
// button1
// 
this->button1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"button1.Backgro…
this->button1->Location = System::Drawing::Point(0, 3);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(360, 292);
this->button1->TabIndex = 0;
this->button1->UseVisualStyleBackCo… = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
// 
// Form1
// 
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::F…
this->ClientSize = System::Drawing::Size(359, 294);
this->Controls->Add(this->button1);
this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));
this->Name = L"Form1";
this->Text = L"Bean";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);

}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
HWND handle;
ShellExecute(handle, (LPCWSTR)"open", (LPCWSTR)"http://www.google.com/", NULL, NULL, SW_SHOWDEFAULT);

}
};
}








------ Rebuild All started: Project: FormTest, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'FormTest', configuration 'Debug|Win32'
Compiling...
stdafx.cpp
Compiling...
AssemblyInfo.cpp
FormTest.cpp
Generating Code...
c:\users\Matt\documents\visual studio 2008\projects\formtest\formtest\form1.h(… : warning C4700: uninitialized local variable 'handle' used
Compiling managed resources...
Read in 2 resources from "c:\Users\Matt\Documents\Visual Studio 2008\Projects\FormTest\FormTest\Form1.re…
Writing resource file... Done.
Compiling resources...
Microsoft ® Windows ® Resource Compiler Version 6.1.6723.1
Copyright © Microsoft Corporation. All rights reserved.
Linking...
FormTest.obj : error LNK2028: unresolved token (0A00000F) "extern "C" struct HINSTANCE__ * __stdcall ShellExecuteW(struct HWND__ *,wchar_t const *,wchar_t const *,wchar_t const *,wchar_t const *,int)" (?ShellExecuteW@@$$J224YGPAUHINSTANCE__@… referenced in function "private: void __clrcall FormTest::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@Form1@FormTest@@$$FA$AAM…
FormTest.obj : error LNK2019: unresolved external symbol "extern "C" struct HINSTANCE__ * __stdcall ShellExecuteW(struct HWND__ *,wchar_t const *,wchar_t const *,wchar_t const *,wchar_t const *,int)" (?ShellExecuteW@@$$J224YGPAUHINSTANCE__@… referenced in function "private: void __clrcall FormTest::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@Form1@FormTes

Is This A Good Question/Topic? 0
  • +

Replies To: Visual C++ Help!

#2 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

Re: Visual C++ Help!

Posted 26 March 2010 - 01:36 AM

hi

The first reported problem is:

Quote

unresolved token (0A00000F) "extern "C" struct HINSTANCE__ * __stdcall ShellExecuteW(struct HWND__ *,wchar_t const *,wchar_t const *,wchar_t const *,wchar_t const *,int)"


Any chance you have missed or added a variable?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1