前田稔(Maeda Minoru)の超初心者のプログラム入門
//Hello.h class HelloClass { public: void HelloMsg(); }; |
//Hello.cpp #include <stdio.h> #include "Hello.h" void HelloClass::HelloMsg() { printf("Hello DLL\n"); } |
// Wrapper.h #pragma once using namespace System; namespace Wrapper { public ref class Wrap { public: HelloClass *cls; Wrap(); //Constructor ~Wrap(); //Destructor void func(); }; } |
//Wrapper.cpp #include "Hello.h" #include "Wrapper.h" #pragma comment(lib,"Hello.lib") using namespace System; namespace Wrapper { Wrap::Wrap() { cls = new HelloClass(); } Wrap::~Wrap() { delete cls; } void Wrap::func() { cls->HelloMsg(); } } |
名前 | 説明 |
---|---|
Wrapper | Wrapper.dll の namespace の名前 |
Wrap | Object Class の名前 |
void func() | "Hello Function DLL\n" を印字するメソッド |
// GcmLcm.h class GcmLcm { public: int gcm(int v1, int v2); int lcm(int v1, int v2); }; |
// GcmLcm.cpp #include "GcmLcm.h" int GcmLcm::gcm(int v1, int v2) { int w1,w2; w1 = v1; w2 = v2; while(w1 != w2) { if (w1 > w2) w1-= w2; else w2-= w1; } return w1; } int GcmLcm::lcm(int v1, int v2) { return v1*v2/gcm(v1,v2); } |
// Wrapper.h #pragma once using namespace System; namespace Wrapper { public ref class Wrap { public: GcmLcm *cls; Wrap(); //Constructor ~Wrap(); //Destructor int Gcm(int v1, int v2); int Lcm(int v1, int v2); }; } |
//Wrapper.cpp #include "GcmLcm.h" #include "Wrapper.h" #pragma comment(lib,"GcmLcm.lib") using namespace System; namespace Wrapper { Wrap::Wrap() { cls = new GcmLcm(); } Wrap::~Wrap() { delete cls; } int Wrap::Gcm(int v1, int v2) { return cls->gcm(v1,v2); } int Wrap::Lcm(int v1, int v2) { return cls->lcm(v1,v2); } } |
名前 | 説明 |
---|---|
Wrapper | Wrapper.dll の namespace の名前 |
Wrap | Object Class の名前 |
int Gcm(int v1, int v2) | GCM を計算するソッド |
int Lcm(int v1, int v2) | LCM を計算するソッド |