C++/CLI関数のインポートエラー

このQ&Aのポイント
  • Visual C++でビルドすると、ConnectionWraps::Class1::GetConnectionのインポートに失敗するエラーが発生します。
  • DLL側のConnectionWraps.hファイルには、ConnectionWraps::Class1クラスとそのメソッドが定義されています。
  • 実行ファイル側のConnectionWrapsTest.cppファイルで、Class1::GetConnectionを呼び出していますが、エラーが発生しています。
回答を見る
  • ベストアンサー

C++/CLI 関数がインポートできない

Visual C++でビルドすると、 1>ConnectionWrapsTest.cpp(12): warning C4679: 'ConnectionWraps::Class1::GetConnection' : メンバーをインポートできませんでした 1> 型 'ConnectionWraps::Class1 ' をアセンブリ 'ConnectionWraps, Version=1.0.4594.40998, Culture=neutral, PublicKeyToken=null' からインポート中に、この診断が発生しました。 という様なエラーがいくつかでて、失敗してしまいます。 何故この様なエラーが出るのか理解出来ません。解決策を教えてください。 DLL側 ------------------------------------------- // ConnectionWraps.h #pragma once using namespace System; using namespace std; #include <string> namespace ConnectionWraps { public ref class Class1 { // TODO: このクラスの、ユーザーのメソッドをここに追加してください。 public: static int GetConnection(string address, string port, string database, string userid, string password); static void CloseConnection(int handle); static int ChangeDatabase(int handle, string databaseName); static int Command(int handle, string sql); }; } -------------------------------------------------- 実行ファイル側 ---------------------------------------------------- // ConnectionWrapsTest.cpp : メイン プロジェクト ファイルです。 #include "stdafx.h" #include <string> using namespace std; using namespace System; using namespace ConnectionWraps; int main(array<System::String ^> ^args) { Console::WriteLine(Class1::GetConnection("a", "a", "a", "a", "a", "a")); return 0; } -------------------------------------------------

質問者が選んだベストアンサー

  • ベストアンサー
  • osamuy
  • ベストアンサー率42% (1231/2878)
回答No.1

Console::WriteLine(Class1::GetConnection(/*address*/"a", /*port*/"a", /*database*/"a", /*userid*/"a", /*password*/"a", /* ?! */"a"));

ps2-arfiu4
質問者

お礼

ありがとうございました。

ps2-arfiu4
質問者

補足

ご指摘のとおり数の数が違うようなのでコードを直してソリューションをリビルドしたのですがほぼ同じエラーが出てきたので、どうやら原因は違うようです。いったい何故エラーが出るのでしょうか? エラー↓ ---------------------------------------------- 2>ConnectionWrapsTest.cpp(12): warning C4679: 'ConnectionWraps::Class1::GetConnection' : メンバーをインポートできませんでした 2> 型 'ConnectionWraps::Class1 ' をアセンブリ 'ConnectionWraps, Version=1.0.4595.35059, Culture=neutral, PublicKeyToken=null' からインポート中に、この診断が発生しました。 2>ConnectionWrapsTest.cpp(12): warning C4679: 'ConnectionWraps::Class1::ChangeDatabase' : メンバーをインポートできませんでした 2> 型 'ConnectionWraps::Class1 ' をアセンブリ 'ConnectionWraps, Version=1.0.4595.35059, Culture=neutral, PublicKeyToken=null' からインポート中に、この診断が発生しました。 2>ConnectionWrapsTest.cpp(12): warning C4679: 'ConnectionWraps::Class1::Command' : メンバーをインポートできませんでした 2> 型 'ConnectionWraps::Class1 ' をアセンブリ 'ConnectionWraps, Version=1.0.4595.35059, Culture=neutral, PublicKeyToken=null' からインポート中に、この診断が発生しました。 2>ConnectionWrapsTest.cpp(12): error C2039: 'GetConnection' : 'ConnectionWraps::Class1' のメンバーではありません。 2> c:\users\inv\documents\visual studio 2010\projects\connectionwraps\debug\connectionwraps.dll : 'ConnectionWraps::Class1' の宣言を確認してください。 2>ConnectionWrapsTest.cpp(12): error C3861: 'GetConnection': 識別子が見つかりませんでした --------------------------------------------------------

関連するQ&A

  • C++/CLIのオブジェクト型配列

    VC++/CLIで、オブジェクト型の配列data、ArrayData(String^ s, int a, int d, double c)でコンストラクタをつくり array<Object^>^ data = gcnew ArrayData(String^ s, int a, double b); でインスタンス化したいのですがうまくいきません。 さらに、他クラスから、d->data[i].aで、data[i]」の配列のうち、整数型変数aを参照したいたいと思っていますがそれも上手くいきません。 例えば data[0]= gcnew ArrayData("山田",30,45.2); data[1]= gcnew ArrayData("高橋",66,43.2); data[2]= gcnew ArrayData("田中",86,62.7); のdata配列を用意します. VC++2005で作成したファイルを載せますので、それに対応したコード(.hファイルと.cppファイル)を教えてくれるとありがたいです。 このままでは、エラーです。内容は、メンバ変数、ドット演算子など。 --File Name:ArrayData.h-- #pragma once using namespace::System; ref class ArrayData { public:array<object^>^ data; public: ArrayData(String^ name,int data1,double data2); }; --File Name:ArrayData.cpp-- #include "StdAfx.h" #include "ArrayData.h" ArrayData::ArrayData() { data= gcnew array<Object^>(5); data[0]= gcnew ArrayData("山田",30,45.2); data[1]= gcnew ArrayData("高橋",66,43.2); data[2]= gcnew ArrayData("田中",86,62.7); } --File Name Form1.h-- #pragma once #include"ArrayData.h" namespace TestDataArray { 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> /// Form1 の概要 /// /// 警告: このクラスの名前を変更する場合、このクラスが依存するすべての .resx ファイルに関連付けられた /// マネージ リソース コンパイラ ツールに対して 'Resource File Name' プロパティを /// 変更する必要があります。この変更を行わないと、 /// デザイナと、このフォームに関連付けられたローカライズ済みリソースとが、 /// 正しく相互に利用できなくなります。 /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: ここにコンストラクタ コードを追加します // ArrayData^ abc = gcnew ArrayData(); //ArrayDataクラスのインスタンス化 int bee= abc->data[0].data1; //data[0]配列のdata1の値(=30)を参照 String^ cee=bee.ToString();  //beeを文字列化 MessageBox::Show(cee); //メッセージボックスにceeを表示 } protected: /// <summary> /// 使用中のリソースをすべてクリーンアップします。 /// </summary> ~Form1() { if (components) { delete components; } } private: /// <summary> /// 必要なデザイナ変数です。 /// </summary> System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// <summary> /// デザイナ サポートに必要なメソッドです。このメソッドの内容を /// コード エディタで変更しないでください。 /// </summary> void InitializeComponent(void) { this->components = gcnew System::ComponentModel::Container(); this->Size = System::Drawing::Size(300,300); this->Text = L"Form1"; this->Padding = System::Windows::Forms::Padding(0); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; } #pragma endregion }; } --File Name:TestDataArray.cpp-- // TestDataArray.cpp : メイン プロジェクト ファイルです。 #include "stdafx.h" #include "Form1.h" using namespace TestDataArray; [STAThreadAttribute] int main(array<System::String ^> ^args) { // コントロールが作成される前に、Windows XP ビジュアル効果を有効にします Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); // メイン ウィンドウを作成して、実行します Application::Run(gcnew Form1()); return 0; }

  • C++

    C++で書いた下記のプログラムが、文字の入力が1023個までなら実行されますが、1024個を超えると実行されません。なぜだか分かる方、教えてください。 #include <iostream> #include <string> using namespace std; int main(void) { string Str; cin >> Str; cout << "here"; }

  • C++, strcpy の warning.

    VC2005 Express Edition を使ってます。 #include <iostream> #include <string> using namespace std; int main() {   char str[10] = "hello";   strcpy(str, "HELLO"); } ↑ こちらをコンパイルすると hello.cpp .\hello.cpp(8) : warning C4996: 'strcpy' was declared deprecated C:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(73) : see declaration of 'strcpy' という警告が出るのはどうしてでしょうか? #include <string.h> も試したのですが同じ警告でした。

  • 【C++】関数ポインタの使い方

    関数ポインタの使い方で悩んでいます。 下記の (1)のようにグローバルメソッドとして定義したメソッドを関数ポインタに代入することは出来るのですが、 (2)のようにクラスのメンバメソッドとして定義したメソッドは関数ポインタに代入することは出来ませんでした。 Error:バインドされた関数へのポインターは関数の呼び出しにのみ使用できます。 というエラーが発生します。 関数ポインタに外部参照でメソッドを代入することは出来ないのでしょうか? -----(1)------------------------------------------------------------------ #include "stdafx.h" #include <iostream> using namespace std; int f(int a, int b){ return a * b; } int _tmain(int argc, _TCHAR* argv[]) { typedef int (* FUNC_POINTER)(int, int); FUNC_POINTER fp; fp = f; cout << fp(1,2) <<endl; getchar(); return 0; } ------------------------------------------------------------------------- -----(2)------------------------------------------------------------------ #include "stdafx.h" #include <iostream> using namespace std; class MPointerList{ public: int f(int a, int b){ return a * b; } }; int _tmain(int argc, _TCHAR* argv[]) { typedef int (* FUNC_POINTER)(int, int); FUNC_POINTER fp; //fp = f; MPointerList mP; fp = mP.f; cout << fp(1,2) <<endl; getchar(); return 0; } -------------------------------------------------------------------------

  • Visual C++ 2008 Express Editionで作ったプログラムがコンパイルできない

    http://www.asahi-net.or.jp/~yf8k-kbys/newcpp3.html このサイトに掲載されていたプログラムをまねて以下のプログラムをかいてみたのですがコンパイルが通りません。 原因などはどこにあるのか教えていただけないでしょうか。 // test003.cpp : メイン プロジェクト ファイルです。 #include "stdafx.h" //using namespace System; using namespace std; int main(array<System::String ^> ^args) { string name; //Console::WriteLine(L"Hello World"); //return 0; cout << "こんにちは。私はコンピュータです。" << endl; cout << "あなたの名前を入力してください。" << endl; cin >> name; cout << name <<"さん。よろしく。" << endl; }

  • 【C++】ヘッダ内でstringを格納する変数の宣

    【C++】ヘッダ内でstringを格納する変数の宣言ができない 下記クラスのように、string型の変数nameを宣言したいのですができません。 どのようにしてstring型データを格納する変数を宣言すればよいのでしょうか? //--------------- //Neko.h #pragma once #include <string> ref class Neko { private: string name; public: Neko(); }; //--------------- //Neko.cpp #include "StdAfx.h" #include "Neko.h" #include <string> using namespace std; Neko::Neko(){ name = "neko"; }

  • Visual Studio 2017C#

    下記のVisual Studio 2017 C# 19行目のXの定義がありません。 と出ました。 11行目で定義していると思うのですけど…。 どういうことなのか教えてください。 ご多忙のところ恐れ入りますが、ご回答のほどよろしくお願いします。 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace jump25 { class Test { public int x = 10; } class Program { public static void Main(string[] args) { Test obj = new Test(); int y = object.x; Console.WriteLine(y); } } }

  • この文章正確ですか?

    #include <string> #include <iostream> using namespace std; int main(){ string s1; s1 = "こんにちわ"; count << s1 << endl; } これをコンパイルしようとしてもできません。 どこが間違っているのでしょうか?

  • shared_ptr クラスについて

    shared_ptrクラスを使いたいのですが、使えません、どうしてでしょうか?ソースはこれです。 #include<iostream> #include <string> #include <fstream> #include<memory> using namespace std; class SMonster{ string name; int power; public: SMonster(); SMonster(int p); ~SMonster(){ }; void SetPower(int p); int GetPower(SMonster& t)const; void walk(const string& str); int GetPoint(void)const; }; class B {}; class D : public B {}; int main(void) { shared_ptr<D> sp0(new D); SMonster m(200); SMonster n(100); std::cout<<m.GetPower(m)<<std::endl; std::cout<<n.GetPower(n)<<std::endl; ShowWindow(10); }

  • 関数名、パラメータは同じで、戻り値によって異なる処理?

    戻り値というより、受け側によって関数の振る舞いを変えたいのですが、 C++では、同名、同パラメータはC2556のコンパイルエラーになります。 Perlでいうリスト値を返すかスカラー値を返すかは呼び出し側によるようなことをしたいのですが、C++では無理でしょうか? 下の例では、//...部分は戻り値によって異なるのでC++のテンプレート?では無理そうですが、そんなことはC++でできるのでしょうか? 似たようなテクニックでも構いませんので、知識の豊富な方、教えてください。 #include <iostream> #include <string> using namespace std; class A { public: A(){} ~A(){} int test(int x, int y){           //... return 0; } string test(int x, int y){ // ... return ""; } }; void main(void){ A a; int ret1 = a.test(1,2); string ret2 = a.test(1,2); cout << endl << "End..." << endl; }