1*dcc6e752SPedro Giffuni /************************************************************************* 2*dcc6e752SPedro Giffuni 3*dcc6e752SPedro Giffuni Copyright 2011 Yuri Dario <mc6530@mclink.it> 4*dcc6e752SPedro Giffuni 5*dcc6e752SPedro Giffuni Licensed under the Apache License, Version 2.0 (the "License"); 6*dcc6e752SPedro Giffuni you may not use this file except in compliance with the License. 7*dcc6e752SPedro Giffuni You may obtain a copy of the License at 8*dcc6e752SPedro Giffuni 9*dcc6e752SPedro Giffuni http://www.apache.org/licenses/LICENSE-2.0 10*dcc6e752SPedro Giffuni 11*dcc6e752SPedro Giffuni Unless required by applicable law or agreed to in writing, software 12*dcc6e752SPedro Giffuni distributed under the License is distributed on an "AS IS" BASIS, 13*dcc6e752SPedro Giffuni WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*dcc6e752SPedro Giffuni See the License for the specific language governing permissions and 15*dcc6e752SPedro Giffuni limitations under the License. 16*dcc6e752SPedro Giffuni 17*dcc6e752SPedro Giffuni ************************************************************************/ 18*dcc6e752SPedro Giffuni 19*dcc6e752SPedro Giffuni #define INCL_DOS 20*dcc6e752SPedro Giffuni #ifdef OS2 21*dcc6e752SPedro Giffuni #include <svpm.h> 22*dcc6e752SPedro Giffuni #else 23*dcc6e752SPedro Giffuni #include <os2.h> 24*dcc6e752SPedro Giffuni #endif 25*dcc6e752SPedro Giffuni #include <dlfcn.h> 26*dcc6e752SPedro Giffuni #include <stdarg.h> 27*dcc6e752SPedro Giffuni #include <stdlib.h> 28*dcc6e752SPedro Giffuni #ifdef TESTME 29*dcc6e752SPedro Giffuni #include <stdio.h> 30*dcc6e752SPedro Giffuni #endif 31*dcc6e752SPedro Giffuni 32*dcc6e752SPedro Giffuni typedef APIRET _PMPRINTF(const char*, ...); 33*dcc6e752SPedro Giffuni typedef _PMPRINTF* PMPRINTF; 34*dcc6e752SPedro Giffuni 35*dcc6e752SPedro Giffuni static void* hmodPmPrintf = NULL; 36*dcc6e752SPedro Giffuni static PMPRINTF pfnPmPrintf = NULL; 37*dcc6e752SPedro Giffuni 38*dcc6e752SPedro Giffuni int _Export debug_printf( const char* format, ...) 39*dcc6e752SPedro Giffuni { 40*dcc6e752SPedro Giffuni va_list args; 41*dcc6e752SPedro Giffuni int cnt; 42*dcc6e752SPedro Giffuni 43*dcc6e752SPedro Giffuni if (hmodPmPrintf == NULL) { 44*dcc6e752SPedro Giffuni // try dll loading 45*dcc6e752SPedro Giffuni hmodPmPrintf = dlopen( "PMPRINTF", 0); 46*dcc6e752SPedro Giffuni if (hmodPmPrintf == NULL) 47*dcc6e752SPedro Giffuni return -1; 48*dcc6e752SPedro Giffuni 49*dcc6e752SPedro Giffuni // search function 50*dcc6e752SPedro Giffuni pfnPmPrintf = dlsym(hmodPmPrintf, "PmPrintfVa"); 51*dcc6e752SPedro Giffuni if (!pfnPmPrintf) 52*dcc6e752SPedro Giffuni return -1; 53*dcc6e752SPedro Giffuni 54*dcc6e752SPedro Giffuni } 55*dcc6e752SPedro Giffuni 56*dcc6e752SPedro Giffuni // function loaded, print data 57*dcc6e752SPedro Giffuni va_start(args, format); 58*dcc6e752SPedro Giffuni cnt = pfnPmPrintf(format, args); 59*dcc6e752SPedro Giffuni va_end(args); 60*dcc6e752SPedro Giffuni 61*dcc6e752SPedro Giffuni return cnt; 62*dcc6e752SPedro Giffuni } 63*dcc6e752SPedro Giffuni 64*dcc6e752SPedro Giffuni 65*dcc6e752SPedro Giffuni #ifdef TESTME 66*dcc6e752SPedro Giffuni int main( void) 67*dcc6e752SPedro Giffuni { 68*dcc6e752SPedro Giffuni printf( "Test PMPRINTF.DLL output, check PM window.\n"); 69*dcc6e752SPedro Giffuni debug_printf( "Test PMPRINTF.DLL output, check PM window."); 70*dcc6e752SPedro Giffuni debug_printf( "Test PMPRINTF.DLL output: integer %d", 12345); 71*dcc6e752SPedro Giffuni debug_printf( "Test PMPRINTF.DLL output: float %f", 123.45); 72*dcc6e752SPedro Giffuni debug_printf( "Test PMPRINTF.DLL output: string '%s'", "Hello World"); 73*dcc6e752SPedro Giffuni exit(0); 74*dcc6e752SPedro Giffuni } 75*dcc6e752SPedro Giffuni #endif // TESTME 76