Sample Program in C++ |
/************************************************************************/ /* Sample program in C++ */ /* CTEST: a Windows API style program */ /* */ /* Author: Killet GeoSoftware Ing.-GbR */ /* and Axel Bieroegel, GTSE mbH */ /* */ /* C++ demonstration program for using geodetic GeoDLL functions */ /* */ /* In the calling directory of the program the files geodll32.dll */ /* and geodllbn.bin must be present. */ /************************************************************************/
// With use of the function LoadLibrary() the program accesses the // functions setunlockcode() and coordtrans3() of Geodll32.dll. With the // function coordtrans3() some calculations are made and represented in a // window.
// Software selling company and author of GeoDLL: // Killet GeoSoftware Ing.-GbR // Escheln 28a // D-47906 Kempen (Germany) // Tel: ++49 / (0)2152 / 961127 // Fax: ++49 / (0)2152 / 961128 // Internet: https://www.killetsoft.de // Email: https://www.killetsoft.de/cgi-bin/mailing/anfrage.pl?lan=d
#include <stdafx.h> #include <windows.h> #include <iostream.h> #include <stdlib.h> #include <stdio.h>
long FAR PASCAL WndProc(HWND hwnd,UINT message, UINT wParam, LONG lParam) { HDC hdc; HPEN hpen; HGDIOBJ hpenOld; PAINTSTRUCT ps; RECT rect; double nKoordXZ_1, nKoordYZ_1, nKoordXZ_2, nKoordYZ_2, nKoordXZ_3, nKoordYZ_3, nKoordXZ_4, nKoordYZ_4; long int BoolRet_1, BoolRet_2, BoolRet_3, BoolRet_4; char Text[100], String1[100], String2[100], String3[100], String4[100]; HINSTANCE hInstance; DWORD LastError;
long int (_stdcall *pFrei) (char*,char*) = NULL;
long int (_stdcall *pTrans) (double,double,short int,short int,short int,double *,double *, short int,short int,short int,short int) = NULL;
// Bind DLL explicitly, since neither GeoDLL32.LIB nor GeoDLL32.DEF // are available. Intercept possible errors. if ((hInstance =::LoadLibrary("geodll32.dll")) != NULL) { if ((pFrei = (long int (_stdcall *) (char *,char *)) ::GetProcAddress(hInstance,"setunlockcode")) == NULL) LastError = GetLastError(); if (pFrei != NULL) { if ((pTrans = (long int (_stdcall *) (double,double,short int,short int,short int,double *,double *, short int,short int,short int,short int)) ::GetProcAddress(hInstance,"coordtrans3")) == NULL) LastError = GetLastError(); } } else LastError = GetLastError();
// Preparation for the text output to the window. switch (message) { case WM_PAINT: hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rect); hpen = CreatePen(PS_SOLID, 6, RGB(0, 0, 255)); hpenOld = SelectObject(hdc, hpen); Rectangle(hdc, rect.left + 10,rect.top + 10,rect.right - 10, rect.bottom - 10); ExtTextOut(hdc, // handle to device context rect.left +20, // x-coordinate of reference point rect.top +20, // y-coordinate of reference point ETO_CLIPPED, // text-output options &rect, // optional clipping / opaquing rect. "String 1", // points to string 0, // number of characters in string NULL); // pointer to array of interchar sp. val.
// Error handling: Output of the error messages if DLL could not be // opened or there is no access to the function coordtrans3(). if (hInstance == NULL) { sprintf (Text," Errorcode = %ld",LastError); ExtTextOut( hdc,rect.left+20,rect.top+40,ETO_CLIPPED,&rect, "DLL geodll32.dll error on open",30,NULL); ExtTextOut( hdc,rect.left+20,rect.top+60,ETO_CLIPPED,&rect, Text,strlen(Text),NULL); } else { ExtTextOut( hdc,rect.left+20,rect.top+40,ETO_CLIPPED,&rect, "DLL geodll32.dll loaded (OK)",28,NULL); if (pTrans == NULL) { sprintf (Text," Errorcode = %ld",LastError); ExtTextOut( hdc,rect.left+20,rect.top+60,ETO_CLIPPED,&rect, "One or more functions not found",31,NULL); ExtTextOut( hdc,rect.left+20,rect.top+80,ETO_CLIPPED,&rect, Text,strlen(Text),NULL); } else ExtTextOut( hdc,rect.left+20,rect.top+60,ETO_CLIPPED,&rect, "All function found (OK)",23,NULL); }
// DLL function call and results output. // The function coordtrans3() can be called without input of the valid // unlock parameters here only during a short time per program run. // Alternatively the function setunlockcode() can be inserted here. After // the input of the valid unlock parameters, which can be acquired from // the software selling company, all restrictions are waived. /* if (pFrei != NULL) BoolRet = pFrei("pszCode","pszLizN"); // with pszCode = char* unlock key // with pszLizN = char* licensee name */
// Calculate four Coordinate Transformations: // Gauss-Krueger (3 degrees wide meridian strips) (strip 4) --> // geographic coordinates without Reference System Transition, // ddmmss notation // Gauss-Krueger (3 degrees wide meridian strips) (strip 2) --> // UTM (native meridian strip) with Reference System Transition // Gauss-Krueger (3 degrees wide meridian strips) (strip 2) --> // UTM (strip32) with Reference System Transition // UTM --> Gauss-Krueger (6 degrees wide meridian strips) // (native meridian strip) with Reference System Transition if (pTrans != NULL) { BoolRet_1 = pTrans(4556879.09,5612654.21,2,1,0, &nKoordXZ_1,&nKoordYZ_1,1,1,1,0); sprintf (String1,"Ret=%1d, KoordXZ=%9.2lf, KoordYZ=%9.2lf", BoolRet_1,nKoordXZ_1,nKoordYZ_1); ExtTextOut( hdc,rect.left+20,rect.top+100,ETO_CLIPPED,&rect, "Ret = trans(4556879.09, 5612654.21, ...)",40,NULL); ExtTextOut(hdc,rect.left+20,rect.top+120,ETO_CLIPPED,&rect, String1,strlen(String1),NULL);
BoolRet_2 = pTrans(2479976.65,5658876.14,2,1,0, &nKoordXZ_2,&nKoordYZ_2,3,2,0,0); sprintf (String2,"Ret=%1d, KoordXZ=%11.2lf, KoordYZ=%10.2lf", BoolRet_2,nKoordXZ_2,nKoordYZ_2); ExtTextOut( hdc,rect.left+20,rect.top+160,ETO_CLIPPED,&rect, "Ret = trans(2479976.65, 5658876.14, ...)",40,NULL); ExtTextOut(hdc,rect.left+20,rect.top+180,ETO_CLIPPED,&rect, String2,strlen(String2),NULL);
BoolRet_3 = pTrans(2479976.65,5658876.14,2,1,0, &nKoordXZ_3,&nKoordYZ_3,3,2,0,32); sprintf (String3,"Ret=%1d, KoordXZ=%11.2lf, KoordYZ=%10.2lf", BoolRet_3,nKoordXZ_3,nKoordYZ_3); ExtTextOut( hdc,rect.left+20,rect.top+220,ETO_CLIPPED,&rect, "Ret = trans(2479976.65, 5658876.14, ...)",40,NULL); ExtTextOut(hdc,rect.left+20,rect.top+240,ETO_CLIPPED,&rect, String3,strlen(String3),NULL);
BoolRet_4 = pTrans(32577386.91,5659050.78,3,2,0, &nKoordXZ_4,&nKoordYZ_4,4,3,0,0); sprintf (String4,"Ret=%1d, KoordXZ=%10.2lf, KoordYZ=%10.2lf", BoolRet_4,nKoordXZ_4,nKoordYZ_4); ExtTextOut( hdc,rect.left+20,rect.top+280,ETO_CLIPPED,&rect, "Ret = trans(32577386.91, 5659050.78, ...)",41,NULL); ExtTextOut(hdc,rect.left+20,rect.top+300,ETO_CLIPPED,&rect, String4,strlen(String4),NULL); }
SelectObject(hdc, hpenOld); DeleteObject(hpen); EndPaint(hwnd, &ps); return 0;
case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }
// Initialize program and generate window. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow) { static char szAppName[] = "CTEST"; HWND hwnd; MSG msg; WNDCLASS wndclass;
if (!hPrevInstance) { wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName;
RegisterClass(&wndclass); }
hwnd = CreateWindow(szAppName, // window class name "CTEST GeoDLL32 Program", // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL); // creation parameters
ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
|