.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 2000-2004 SAP AG$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $SQL$Project Distributed Database System$VPR30WC$
.tt 2 $$$
.tt 3 $BurkhardD$C-Precompiler Runtime LibEntry$2001-01-15$
***********************************************************
.nf

.nf


    ========== licence begin  GPL
    Copyright (c) 2000-2004 SAP AG

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end

.fo


.fo
Module  :
=========
.sp
Purpose :
.CM *-END-* purpose -------------------------------------
Define  :        
#ifndef DEBUG
#line 20 "vpr30wc"
#endif
#ifdef WIN32
#endif /* WIN32 */
.CM *-END-* define --------------------------------------
Use     :
.CM *-END-* use -----------------------------------------
Synonym :
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : BurkhardD
.sp
.cp 3
Created : 1997-10-29
.sp
.cp 3
Version : 1997-10-29
.sp
.cp 3
Release :      Date : 2001-01-15
.sp
Specification:
.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:
.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:
.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.CM -lll-
Code    :
#ifndef DEBUG
#line 67 "vpr30wc"
#endif
/* GLOBALS */
HWND pr30hWnd;
typedef struct {
   int version;
   HANDLE hwnd;
   int status;
   char FileName[260];
   int TraceLevel;
} pr30TraceStatus;

/* EXTERNALS */
extern char *m90_tr_profentry;
extern char *m90_tr_appname;
extern HINSTANCE m90s_hModule;
#define PR30_CLASSNAME P07_PRODNAME" "P07_PC_RUNTIME
/* MACROS */

/* PROTOTYPES */
LONG FAR PASCAL pr30WndProc(HWND hw, UINT iMsg, WPARAM uP1, LPARAM lP2);

int FAR PASCAL pr30LibMain(
		       HANDLE	hModule,
		       DWORD   dwReason,
		       LPVOID  lpReserved)
{
  switch (dwReason) {
  case DLL_PROCESS_ATTACH: {
    WNDCLASS wc;
    m90s_hModule = hModule;
    m90_tr_profentry = "cpctrace";

    M90TRACEINIT(88);
    if (m90_trace_status == 1) {
      CHAR FAR *env = GetEnvironmentStrings();
      char szBuf[MAX_PATH];
      WORD wReturn;
      GetModuleFileName(hModule, szBuf, sizeof(szBuf));
      M90TRACE(M90_TR_STRING, "DRIVER", szBuf);
      M90TRACE(M90_TR_STRING, "VERSION", P07_RELSTR);
      GetModuleFileName(NULL, szBuf, sizeof(szBuf));
      M90TRACE(M90_TR_STRING, "Application", szBuf);
      M90TRACE(M90_TR_STRING, "CommandLine", GetCommandLine());
      while (*env != '\0') {
	if (!memcmp(env, "PATH=", sizeof("PATH=")-1)) {
	  M90TRACE(M90_TR_STRING, "env", env);
	}
	if (!memcmp(env, "DBROOT=", sizeof("DBROOT=")-1)) {
	  M90TRACE(M90_TR_STRING, "env", env);
	}
	env += strlen(env)+1;
      }
      wReturn = GetSystemDirectory(szBuf, sizeof(szBuf));
      if (wReturn) {	  
	wReturn = (wReturn > sizeof(szBuf)) ? sizeof(szBuf) : wReturn;
	M90TRACELEN(M90_TR_STRING_LEN, "SystemDirectory", szBuf, wReturn);
      }
      wReturn = _getdrive();
      if (_getdcwd(wReturn, szBuf, sizeof(szBuf)))
	M90TRACE(M90_TR_STRING, "CurrentPath", szBuf);       
    }    
    wc.style=CS_VREDRAW | CS_HREDRAW; 
    wc.lpfnWndProc=(WNDPROC) pr30WndProc;
    wc.cbClsExtra=0; 
    wc.cbWndExtra=0;
    wc.hInstance=hModule; 
    wc.hIcon=NULL; //(HICON)ICO_MAIN; 
    wc.hCursor=NULL; // LoadCursor(0,IDC_ARROW);
    wc.hbrBackground=(HBRUSH)(COLOR_BACKGROUND);
    wc.lpszMenuName=0;
    wc.lpszClassName="SAP SAPDB (C-PRECOMPILER)"; 

    if (!RegisterClass(&wc)) {
      LPVOID lpMsgBuf;
      FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
		     (LPTSTR) &lpMsgBuf, 0, NULL );
      LocalFree(lpMsgBuf);
    }
    {
      char szBuf[MAX_PATH];      
      GetModuleFileName(NULL, szBuf, sizeof(szBuf));      
      pr30hWnd = CreateWindow(P07_PC_RUNTIME" "P07_PC_RUNTIME, szBuf, 
			      WS_OVERLAPPEDWINDOW, 
			      CW_USEDEFAULT, 0, 
			      CW_USEDEFAULT, 0, 
			      HWND_DESKTOP, 0, m90s_hModule, NULL);
      if (pr30hWnd = 0) {
	LPVOID lpMsgBuf;
	FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
		       NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
		       (LPTSTR) &lpMsgBuf, 0, NULL );
	LocalFree(lpMsgBuf);
      }
    }
    break;
  }
  case DLL_THREAD_ATTACH: {
    break;
  }
  case DLL_THREAD_DETACH: {
    break;
  }
  case DLL_PROCESS_DETACH: {
    if (pr30hWnd)
      DestroyWindow(pr30hWnd);
    UnregisterClass("SAP SAPDB (C-PRECOMPILER)", m90s_hModule);
    sqlfinish(FALSE);
    break;
  }
  }
  return TRUE;
}

LONG FAR PASCAL pr30WndProc(HWND hw, UINT iMsg, WPARAM uP1, LPARAM lP2)
{
   LONG ret=FALSE;
   switch (iMsg) {
      case WM_CREATE: {
	 break;
      }
      case WM_COMMAND: {
	 switch ((WPARAM) LOWORD(uP1)) {
	 }
	 break;
      }
      case WM_DESTROY: {
	 break;
      }
      case WM_COPYDATA:{
	 COPYDATASTRUCT *pcds=(COPYDATASTRUCT *)lP2;	 
	 pr30TraceStatus *s;
	 if (pcds) {
	    switch (pcds->dwData) {
	       case (1): {
		  s=(pr30TraceStatus*) pcds->lpData;
		  if (s) {		     
		     M90TRACE(M90_TR_SWORD,"(WM_COPYDATA)", &pcds->cbData);
		     M90TRACE(M90_TR_STRING, "FileName", s->FileName);	    
		     M90TRACE(M90_TR_SDWORD, "TraceLevel", &s->TraceLevel);
		     if (s->status == 1) {
			mt90TraceSwitch(-1);
		     }
		     if (s->status == 2) {
			mt90SetTraceFileName(s->FileName);
			mt90TraceSwitch(s->TraceLevel);
		     }
		  }
		  ret = TRUE;
		  break;
	       }		  
	    }
	 }
	 break;
      }      
   } /* switch */
   if (ret == FALSE) {
      ret = DefWindowProc(hw,iMsg,uP1,lP2);
   }
   return ret;
}

.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
