外部プロシージャの作成
第3世代プログラミング言語を使用して、作成したファンクションをDLLに組み込み、EXTPROC
によって起動することができます。
次のコードは、Microsoft Visual C++で記述したFIND_MAX
という外部プロシージャの簡単な例です。
注意:
外部プロシージャは、DLLに組み込まれるため、明示的にエクスポートする必要があります。この例では、DLLEXPORT
という記憶域のクラス修飾子によって、ファンクションFIND_MAX
をDynamic Link Libraryからエクスポートします。
#include <windows.h> #define NullValue -1 /* This function tests if x is at least as big as y. */ long __declspec(dllexport) find_max(long x, short x_indicator, long y, short y_indicator, short *ret_indicator) { /* It can be tricky to debug DLL's that are being called by a process that is spawned only when needed, as in this case. Therefore try using the DebugBreak(); command. This starts your debugger. Uncomment the line with DebugBreak(); in it and you can step right into your code. */ /* DebugBreak(); */ /* First check to see if you have any nulls. */ /* Just return a null if either x or y is null. */ if ( x_indicator==NullValue || y_indicator==NullValue) { *ret_indicator = NullValue; return(0); } else { *ret_indicator = 0; /* Signify that return value is not null. */ if (x >= y) return x; else return y; } }
親トピック: 外部プロシージャの構築について