AnsiToWide function

AnsiToWide function

Postby pawelu » Sun Oct 29, 2006 6:56 pm

Antonio,

Is there possible in a new build to use AnsiToWide function ? Previously this function is exists visible - now this don't. Below is sample where I use this useful function. Program source probable must compile with -TP switch. Compile without this switch generates many compilation errors.

Regards
Pawel

Compilation errors:
Harbour Compiler Alpha build 46.2 (Flex)
Copyright 1999-2006, http://www.harbour-project.org/
Compiling 'TESTRUN.prg'...

Lines 58, Functions/Procedures 1
Generating C source output to 'TESTRUN.c'... Done.
TESTRUN.C
TESTRUN.prg(23) : warning C4047: 'function' : 'int ' differs in levels of indirection from 'void *'
TESTRUN.prg(23) : warning C4024: 'CreateProcessW' : different types for formal and actual parameter 5
TESTRUN.prg(23) : warning C4047: 'function' : 'unsigned long ' differs in levels of indirection from 'void *'
TESTRUN.prg(23) : warning C4024: 'CreateProcessW' : different types for formal and actual parameter 6

Link errors (compile with -TP switch):
Creating library TESTRUN.lib and object TESTRUN.exp
TESTRUN.OBJ : error LNK2019: unresolved external symbol "unsigned short * __cdecl AnsiToWide(char *)" (?AnsiToWide@@YAPAGPAD@Z) referenced in function HB_FUN_RUNEXE
TESTRUN.exe : fatal error LNK1120: 1 unresolved externals

Code: Select all  Expand view
Function TestRun ()

   RunExe ('Prog.Exe', 'param1')   

Return .T.

#pragma BEGINDUMP

#include <hbapi.h>
#include <hbapirdd.h>
#include <windows.h>
#include <aygshell.h>

LPWSTR AnsiToWide (char *);

HB_FUNC (RUNEXE)
{
   PROCESS_INFORMATION pi;
   LPSTR lpExe = hb_parc (1);
   LPSTR lpCmd = hb_parc (2);
   DWORD dwExit;
   DWORD dwSleep = 50;
   DWORD dwTime = 0;
   BOOL bErr = FALSE;

   if (!CreateProcess (AnsiToWide (lpExe), AnsiToWide (lpCmd), NULL, NULL, NULL, NULL, NULL, NULL, NULL, &pi))
   {
      hb_retl (FALSE);
   }
   else
   {
      do
      {
         Sleep (dwSleep);
         GetExitCodeProcess (pi.hProcess, &dwExit);
         dwTime += dwSleep;
         if (dwTime >= (1000 * 60 * 5)) // 5 minutes delay
            {
            TerminateProcess (pi.hProcess, dwExit);
            bErr = TRUE;
            break;
            }
      }
      while (dwExit == STILL_ACTIVE);
      CloseHandle (pi.hThread);
      CloseHandle (pi.hProcess);
      if (bErr)
         hb_retl (FALSE);
      else
         hb_retl (TRUE);
   }
}

#pragma ENDDUMP
pawelu
 
Posts: 126
Joined: Thu Oct 06, 2005 10:18 pm
Location: Poland

Postby Antonio Linares » Sun Oct 29, 2006 7:08 pm

Pawel,

Don't use clarm.exe -TP flag. Here this code works fine:

MsgInfo( WideToAnsi( AnsiToWide( "Hello" ) ) ) // Hello is shown
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby pawelu » Sun Oct 29, 2006 7:09 pm

Antonio,

This "error" is warning but compilation with -TP don't generates any warning and erros.

Pawel
pawelu
 
Posts: 126
Joined: Thu Oct 06, 2005 10:18 pm
Location: Poland

Postby pawelu » Sun Oct 29, 2006 7:25 pm

Antonio,

This is my library what I use in my program. This use DataReelCe library for HTTP download file. Where I compile it without -Tp switch error log is created. Below a source and sample.

Regards
Pawel

// compilation error
Lib03.C
c:\vce\include\datareelce\strutil.h(134) : error C2061: syntax error : identifier 'gxwchar'
c:\vce\include\datareelce\strutil.h(134) : error C2059: syntax error : ';'
c:\vce\include\datareelce\strutil.h(135) : error C2449: found '{' at file scope (missing function header?)
c:\vce\include\datareelce\strutil.h(151) : error C2059: syntax error : '}'
c:\vce\include\datareelce\strutil.h(161) : error C2054: expected '(' to follow 'inline'
c:\vce\include\datareelce\strutil.h(161) : error C2085: 'gxstrcpy' : not in formal parameter list
c:\vce\include\datareelce\strutil.h(161) : error C2143: syntax error : missing ';' before '{'
c:\vce\include\datareelce\strutil.h(164) : error C2054: expected '(' to follow 'inline'
c:\vce\include\datareelce\strutil.h(164) : error C2085: 'gxstrlen' : not in formal parameter list
c:\vce\include\datareelce\strutil.h(164) : error C2143: syntax error : missing ';' before '{'
c:\vce\include\datareelce\strutil.h(165) : error C2054: expected '(' to follow 'inline'
c:\vce\include\datareelce\strutil.h(165) : error C2085: 'gxstrcat' : not in formal parameter list
c:\vce\include\datareelce\strutil.h(165) : error C2143: syntax error : missing ';' before '{'
c:\vce\include\datareelce\strutil.h(166) : error C2054: expected '(' to follow 'inline'
c:\vce\include\datareelce\strutil.h(166) : error C2085: 'gxstrcmp' : not in formal parameter list
c:\vce\include\datareelce\strutil.h(166) : error C2143: syntax error : missing ';' before '{'
c:\vce\include\datareelce\strutil.h(175) : error C2143: syntax error : missing '{' before '*'
c:\vce\include\datareelce\strutil.h(175) : error C2143: syntax error : missing ')' before '*'
c:\vce\include\datareelce\strutil.h(175) : error C2143: syntax error : missing '{' before '*'
c:\vce\include\datareelce\strutil.h(175) : warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
c:\vce\include\datareelce\strutil.h(175) : error C2143: syntax error : missing ';' before '*'
c:\vce\include\datareelce\strutil.h(175) : error C2059: syntax error : ')'
c:\vce\include\datareelce\strutil.h(176) : error C2143: syntax error : missing ')' before '*'
c:\vce\include\datareelce\strutil.h(176) : error C2143: syntax error : missing '{' before '*'
c:\vce\include\datareelce\strutil.h(176) : error C2059: syntax error : ')'
c:\vce\include\datareelce\strutil.h(177) : error C2143: syntax error : missing '{' before '*'
c:\vce\include\datareelce\strutil.h(177) : error C2143: syntax error : missing ')' before '*'
c:\vce\include\datareelce\strutil.h(177) : error C2143: syntax error : missing '{' before '*'
c:\vce\include\datareelce\strutil.h(177) : warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
c:\vce\include\datareelce\strutil.h(177) : error C2143: syntax error : missing ';' before '*'
c:\vce\include\datareelce\strutil.h(177) : error C2059: syntax error : ')'
c:\vce\include\datareelce\strutil.h(178) : error C2143: syntax error : missing ')' before '*'
c:\vce\include\datareelce\strutil.h(178) : error C2143: syntax error : missing '{' before '*'
c:\vce\include\datareelce\strutil.h(178) : warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
c:\vce\include\datareelce\strutil.h(178) : error C2143: syntax error : missing ';' before '*'
c:\vce\include\datareelce\strutil.h(178) : error C2059: syntax error : ')'
c:\vce\include\datareelce\strutil.h(185) : error C2146: syntax error : missing ')' before identifier 'st'
c:\vce\include\datareelce\strutil.h(185) : error C2081: 'gxStringType' : name in formal parameter list illegal
c:\vce\include\datareelce\strutil.h(185) : error C2061: syntax error : identifier 'st'
c:\vce\include\datareelce\strutil.h(185) : error C2059: syntax error : ';'
c:\vce\include\datareelce\strutil.h(185) : error C2059: syntax error : ')'
c:\vce\include\datareelce\strutil.h(190) : error C2146: syntax error : missing ')' before identifier 'st'
c:\vce\include\datareelce\strutil.h(190) : error C2081: 'gxStringType' : name in formal parameter list illegal
c:\vce\include\datareelce\strutil.h(190) : error C2061: syntax error : identifier 'st'
c:\vce\include\datareelce\strutil.h(190) : error C2059: syntax error : ';'
c:\vce\include\datareelce\strutil.h(190) : error C2059: syntax error : ','
c:\vce\include\datareelce\strutil.h(190) : error C2059: syntax error : ')'
c:\vce\include\datareelce\strutil.h(193) : error C2146: syntax error : missing ')' before identifier 'st'
c:\vce\include\datareelce\strutil.h(193) : error C2081: 'gxStringType' : name in formal parameter list illegal
c:\vce\include\datareelce\strutil.h(193) : error C2061: syntax error : identifier 'st'
c:\vce\include\datareelce\strutil.h(193) : error C2059: syntax error : ';'
c:\vce\include\datareelce\strutil.h(193) : error C2059: syntax error : ','
c:\vce\include\datareelce\strutil.h(194) : error C2059: syntax error : ')'
c:\vce\include\datareelce\strutil.h(197) : error C2143: syntax error : missing ')' before '='
c:\vce\include\datareelce\strutil.h(197) : error C2072: 'Unicode2ASCII' : initialization of a function
c:\vce\include\datareelce\strutil.h(198) : error C2059: syntax error : 'type'
c:\vce\include\datareelce\strutil.h(198) : error C2059: syntax error : ')'
c:\vce\include\datareelce\strutil.h(199) : error C2143: syntax error : missing ')' before '='
c:\vce\include\datareelce\strutil.h(199) : error C2072: 'ASCII2Unicode' : initialization of a function
c:\vce\include\datareelce\strutil.h(200) : error C2370: 'wchar_t' : redefinition; different storage class
c:\vce\include\arm\stdlib.h(58) : see declaration of 'wchar_t'
c:\vce\include\datareelce\strutil.h(200) : error C2143: syntax error : missing ';' before '*'
c:\vce\include\datareelce\strutil.h(200) : error C2059: syntax error : ')'
c:\vce\include\datareelce\strutil.h(201) : error C2143: syntax error : missing ')' before '*'
c:\vce\include\datareelce\strutil.h(201) : error C2143: syntax error : missing '{' before '*'
c:\vce\include\datareelce\strutil.h(202) : error C2059: syntax error : 'type'
c:\vce\include\datareelce\strutil.h(203) : error C2059: syntax error : ')'
c:\vce\include\datareelce\strutil.h(204) : error C2143: syntax error : missing ')' before '*'
c:\vce\include\datareelce\strutil.h(204) : error C2143: syntax error : missing '{' before '*'
c:\vce\include\datareelce\strutil.h(204) : error C2059: syntax error : 'type'
c:\vce\include\datareelce\strutil.h(205) : error C2059: syntax error : ')'
c:\vce\include\datareelce\strutil.h(206) : error C2143: syntax error : missing '{' before '*'
c:\vce\include\datareelce\strutil.h(206) : error C2143: syntax error : missing ')' before '='
c:\vce\include\datareelce\strutil.h(206) : error C2072: 'ASCII2gxwchar_t' : initialization of a function
c:\vce\include\datareelce\strutil.h(207) : error C2143: syntax error : missing ';' before '*'
c:\vce\include\datareelce\strutil.h(207) : error C2374: 'nsptr' : redefinition; multiple initialization
c:\vce\include\datareelce\strutil.h(200) : see declaration of 'nsptr'
c:\vce\include\datareelce\strutil.h(207) : error C2059: syntax error : ')'
c:\vce\include\datareelce\strutil.h(208) : error C2143: syntax error : missing '{' before '*'
c:\vce\include\datareelce\strutil.h(209) : error C2143: syntax error : missing ')' before '='
c:\vce\include\datareelce\strutil.h(209) : error C2072: 'Unicode2gxwchar_t' : initialization of a function
c:\vce\include\datareelce\strutil.h(210) : error C2143: syntax error : missing ';' before '*'
c:\vce\include\datareelce\strutil.h(210) : error C2374: 'nsptr' : redefinition; multiple initialization
c:\vce\include\datareelce\strutil.h(200) : see declaration of 'nsptr'
c:\vce\include\datareelce\strutil.h(210) : error C2059: syntax error : ')'
c:\vce\include\datareelce\strutil.h(213) : error C2054: expected '(' to follow 'inline'
c:\vce\include\datareelce\strutil.h(213) : error C2085: 'gxLTCHAR' : not in formal parameter list
c:\vce\include\datareelce\strutil.h(213) : error C2143: syntax error : missing ';' before '{'
c:\vce\include\datareelce\strutil.h(217) : error C2054: expected '(' to follow 'inline'
c:\vce\include\datareelce\strutil.h(217) : error C2085: 'gxLTCHAR' : not in formal parameter list
c:\vce\include\datareelce\strutil.h(217) : error C2143: syntax error : missing ';' before '{'
c:\vce\include\datareelce\strutil.h(221) : error C2054: expected '(' to follow 'inline'
c:\vce\include\datareelce\strutil.h(221) : error C2085: 'gxLTCHAR' : not in formal parameter list
c:\vce\include\datareelce\strutil.h(221) : error C2143: syntax error : missing ';' before '{'
c:\vce\include\datareelce\strutil.h(225) : error C2054: expected '(' to follow 'inline'
c:\vce\include\datareelce\strutil.h(225) : error C2085: 'gxLTCHAR' : not in formal parameter list
c:\vce\include\datareelce\strutil.h(225) : error C2143: syntax error : missing ';' before '{'
c:\vce\include\datareelce\strutil.h(229) : error C2054: expected '(' to follow 'inline'
c:\vce\include\datareelce\strutil.h(229) : error C2143: syntax error : missing ')' before '*'
c:\vce\include\datareelce\strutil.h(229) : error C2085: 'gxLTCHAR' : not in formal parameter list
c:\vce\include\datareelce\strutil.h(229) : error C2143: syntax error : missing ';' before '*'
c:\vce\include\datareelce\strutil.h(229) : error C2059: syntax error : ')'
c:\vce\include\datareelce\strutil.h(233) : error C2054: expected '(' to follow 'inline'
c:\vce\include\datareelce\strutil.h(233) : error C2146: syntax error : missing ')' before identifier 'c'
c:\vce\include\datareelce\strutil.h(233) : error C2085: 'gxLTCHAR' : not in formal parameter list
c:\vce\include\datareelce\strutil.h(233) : error C2146: syntax error : missing ',' before identifier 'c'
c:\vce\include\datareelce\strutil.h(233) : error C2059: syntax error : 'type'
c:\vce\include\datareelce\strutil.h(233) : fatal error C1003: error count exceeds 100; stopping compilation
// end error

Code: Select all  Expand view
Function Test ()

   Local x := 0

Return .T.

#pragma BEGINDUMP

#include <hbapi.h>
#include <hbapirdd.h>

#include <windows.h>
#include <aygshell.h>
#include <gxshttp.h>
#include <gxshttpc.h>
#include <dfileb.h>
#include <gxs_ver.h>
#include <gxscomm.h>
#include <objbase.h>
#include <initguid.h>
#include <connmgr.h>
#include <wininet.h>
#include <tlhelp32.h>

#define MAX_TASKS 256
#define PROCESS_SIZE 128
#define TITLE_SIZE 64

typedef struct _TASK_LIST
{
   DWORD cntUsage;
   DWORD dwProcessId;
   DWORD dwInheritedFromProcessId;
   DWORD cntThreads;
   DWORD th32ModuleID;
   DWORD th32DefaultHeapID;
   LONG  pcPriClassBase;
   BOOL  flags;
   HWND  hwnd;
   TCHAR ProcessName[PROCESS_SIZE];
   TCHAR WindowTitle[TITLE_SIZE];
}
TASK_LIST, *PTASK_LIST;

LPWSTR AnsiToWide (char *);
dwCount);
DWORD dwCount, DWORD dwTimeout);
DWORD GetTaskListCE (PTASK_LIST pTask, DWORD dwNumTasks);
BOOL KillProcess (PTASK_LIST tlist, BOOL fForce = TRUE);

gxSerialComm dev;

// 2005-11-13 22:09:41
// puste menu
HB_FUNC (EMPTYMENU)
{
   SHINITDLGINFO shidi;
   HWND hWnd = (HWND) hb_parnl (1);

   shidi.dwMask  = SHIDIM_FLAGS;
   shidi.hDlg    = hWnd;
   shidi.dwFlags = SHIDIF_EMPTYMENU;
   SHInitDialog (&shidi);
}

// 2005-11-28 22:01:01
// opoznienie
HB_FUNC (DELAY)
{
   DWORD dwSleep = (DWORD) hb_parnl (1);
   Sleep (dwSleep);
}

// 2006-04-10 09:28:51
// informacje o stanie baterii
HB_FUNC (BATTERYLIFE)
{
   BOOL iRet;
   SYSTEM_POWER_STATUS_EX status;
   iRet = GetSystemPowerStatusEx (&status, TRUE);

   hb_retnl ((INT) status.BatteryLifePercent);
}

// 2006-04-10 09:29:25
// informacja o ilosci wolnego miejsca
HB_FUNC (DISKFREE)
{
  BOOL iRet;
  unsigned __int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;

  iRet = GetDiskFreeSpaceEx (NULL,
  (PULARGE_INTEGER) &i64FreeBytesToCaller,
  (PULARGE_INTEGER) &i64TotalBytes,
  (PULARGE_INTEGER) &i64FreeBytes);
  hb_retnl ((ULONG) i64FreeBytes);
}

// 2006-04-10 09:29:50
// utworzenie procesu
HB_FUNC (MOBIEXE)
{
   PROCESS_INFORMATION pi;
   LPSTR lpExe = hb_parc (1);
   LPSTR lpCmd = hb_parc (2);
   // int iTime = (ISNIL (3) ? 5 : (int) hb_parni (3));
   DWORD dwExit;
   DWORD dwSleep = 50;
   DWORD dwTime = 0;
   BOOL bErr = FALSE;

   // if (iTime <= 0) iTime = 5;

   if (!CreateProcess (AnsiToWide (lpExe), AnsiToWide (lpCmd), NULL, NULL, NULL, NULL, NULL, NULL, NULL, &pi))
   {
      hb_retl (FALSE);
   }
   else
   {
      do
      {
         Sleep (dwSleep);
         GetExitCodeProcess (pi.hProcess, &dwExit);
         dwTime += dwSleep;
         if (dwTime >= (1000 * 60 * 5)) // 5 minut
            {
            TerminateProcess (pi.hProcess, dwExit);
            bErr = TRUE;
            break;
            }
      }
      while (dwExit == STILL_ACTIVE);
      CloseHandle (pi.hThread);
      CloseHandle (pi.hProcess);
      if (bErr)
         hb_retl (FALSE);
      else
         hb_retl (TRUE);
   }
}

// 2006-04-10 09:30:02
// dlugosc pola
HB_FUNC (FIELDSIZE)
{
   USHORT uiField;
   LPFIELD pField;
   AREAP pArea;

   uiField = hb_parni (1);
   pArea = (AREAP) hb_rddGetCurrentWorkAreaPointer ();
   pField = pArea->lpFields + uiField - 1;

   hb_retni (pField->uiLen);
}

// 2006-04-10 09:30:09
// dlugosc pola
HB_FUNC (FIELDDECI)
{
   USHORT uiField;
   LPFIELD pField;
   AREAP pArea;

   uiField = hb_parni (1);
   pArea = (AREAP) hb_rddGetCurrentWorkAreaPointer ();
   pField = pArea->lpFields + uiField - 1;

   hb_retni (pField->uiDec);
}

// 2006-04-18 09:29:27
// pobranie pliku z serwera HTTP
HB_FUNC (HTTPDOWNLOAD)
{
  const char *URL = hb_parc (1);
  gxsHTTPClient client;
  gxsURL url;
  gxsURLInfo u;

  if (!url.ParseURL (URL, u)) hb_retl (FALSE);
  gxString sbuf (u.dir);
  if (u.file == "?")
  {
    while (sbuf.DeleteBeforeIncluding ("/"));
    u.file = sbuf;
    u.dir.DeleteAfterIncluding (sbuf.c_str ());
  }
  if (!u.file) hb_retl (FALSE);

  DiskFileB outfile (u.file.c_str (), DiskFileB::df_WRITEONLY, DiskFileB::df_CREATE);
  if (!outfile) hb_retl (FALSE);

  gxsHTTPHeader hdr;
  if (client.RequestHeader (u, hdr) != 0) hb_retl (FALSE);
  if (client.RequestFile (u, hdr, outfile.df_FileStream ()) != 0) hb_retl (FALSE);
  client.Flush ();
  outfile.df_Close ();
  hb_retl (TRUE);
}

// 2006-04-18 09:29:32
// wywolanie polaczenia internetowego
HB_FUNC (GPRSCONNECTION)
{
   // int iRet = ISNIL (1) ? 6 : hb_parni (1);
   HANDLE phWebConnection = NULL;
   DWORD pdwStatus = 0;

   ConnMgrConnectionStatus (phWebConnection, &pdwStatus);
   if (pdwStatus == CONNMGR_STATUS_CONNECTED)
   {
      hb_retl (TRUE);
   }
   else
   {
      CONNMGR_CONNECTIONINFO sConInfo;
      memset (&sConInfo,0, sizeof (CONNMGR_CONNECTIONINFO));
      sConInfo.cbSize = sizeof (CONNMGR_CONNECTIONINFO);
      sConInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
      sConInfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
      sConInfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP;
      sConInfo.bExclusive = FALSE;
      sConInfo.bDisabled = FALSE;
      sConInfo.guidDestNet = IID_DestNetInternet;

      if (ConnMgrEstablishConnection (&sConInfo, &phWebConnection) == S_OK)
      {
         for (unsigned int k = 0; k < 8; k ++)
         {
            ConnMgrConnectionStatus(phWebConnection,&pdwStatus);
            if (pdwStatus == CONNMGR_STATUS_CONNECTED)
            {
               hb_retl (TRUE);
            }
            else
            {
               if (pdwStatus == CONNMGR_STATUS_CONNECTIONCANCELED || pdwStatus == CONNMGR_STATUS_WAITINGCONNECTIONABORT)
               {
                  hb_retl (FALSE);
               }
               Sleep (4000);
               ConnMgrConnectionStatus (phWebConnection, &pdwStatus);
               if (pdwStatus == CONNMGR_STATUS_WAITINGCONNECTION)
               {}
               if (pdwStatus == CONNMGR_STATUS_CONNECTIONCANCELED || pdwStatus == CONNMGR_STATUS_WAITINGCONNECTIONABORT)
               {
                  hb_retl (FALSE);
               }
            }
         }
         hb_retl (FALSE);
      }
      else
      {
         hb_retl (FALSE);
      }
   }
}

// 2006-05-11 20:29:54
HB_FUNC (MOBITASK)
{
   DWORD i = 0, j = 0, k = 0;
   TASK_LIST tlist[MAX_TASKS];
   DWORD numTasks;
   BOOL bRet = FALSE;

   k = GetCurrentProcessId ();
   memset (&tlist, 0, sizeof (TASK_LIST) * MAX_TASKS);
   numTasks = GetTaskListCE (tlist, MAX_TASKS);
   for (i = 0; i < numTasks; i ++)
   {
      if (k != tlist[i].dwProcessId && (_tcscmp (_tcsupr (tlist[i].ProcessName), TEXT ("MOBI.EXE")) == 0 || _tcscmp (_tcsupr (tlist[i].ProcessName), TEXT ("MOBISYNC.EXE")) == 0))
      {
         KillProcess (&tlist[i]);
         bRet = TRUE;
      }
   }
   hb_retl (bRet);
}

// 2006-05-11 20:02:13
DWORD GetTaskListCE (PTASK_LIST pTask, DWORD dwNumTasks)
{
   HINSTANCE hProcessSnap = NULL;
   PROCESSENTRY32 pe32 = {0};
   DWORD dwTaskCount = 0;

   if (dwNumTasks == 0) return 0;
   hProcessSnap = (HINSTANCE) CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
   if (hProcessSnap == (HANDLE) -1) return 0;
   dwTaskCount = 0;
   pe32.dwSize = sizeof (PROCESSENTRY32);
   if (Process32First (hProcessSnap, &pe32))
   {
      do
      {
         LPTSTR pCurChar;
         if (_tcsstr (pe32.szExeFile, L"\\"))
             pCurChar = _tcsrchr (pe32.szExeFile, '\');
         else
             pCurChar = pe32.szExeFile;
         lstrcpy (pTask->ProcessName, pCurChar);
         pTask->flags = 0;
         pTask->dwProcessId = pe32.th32ProcessID;
         pTask->cntThreads = pe32.cntThreads;
         pTask->cntUsage = pe32.cntUsage;
         pTask->dwInheritedFromProcessId = pe32.th32ParentProcessID;
         pTask->th32ModuleID = pe32.th32ModuleID;
         ++ dwTaskCount;
         ++ pTask;
      }
      while (dwTaskCount < dwNumTasks && Process32Next (hProcessSnap, &pe32));
   }
   else dwTaskCount = 0;
   CloseHandle (hProcessSnap);
   CloseToolhelp32Snapshot (hProcessSnap);
   return dwTaskCount;
}

// 2006-05-11 20:02:10
BOOL KillProcess (PTASK_LIST tlist, BOOL fForce)
{
   HANDLE hProcess;

   if (fForce || !tlist->hwnd)
   {
      hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, tlist->dwProcessId);
      if (hProcess)
      {
         hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, tlist->dwProcessId);
         if (hProcess == NULL)
         {
            return FALSE;
         }
         if (!TerminateProcess (hProcess, 1))
         {
            CloseHandle (hProcess);
            return FALSE;
         }
         CloseHandle (hProcess);
         return TRUE;
      }
   }
   PostMessage (tlist->hwnd, WM_CLOSE, 0, 0);
   return TRUE;
}

#pragma ENDDUMP
pawelu
 
Posts: 126
Joined: Thu Oct 06, 2005 10:18 pm
Location: Poland

Postby Antonio Linares » Sun Oct 29, 2006 7:48 pm

Pawel,

Your above code is leaking memory. BTW you may use FWPPC WinExec().

This is the fix for your code:
Code: Select all  Expand view
   LPSTR lpExe = hb_parc (1);
   LPSTR lpCmd = hb_parc (2);
   LPWSTR lpWExe = AnsiToWide( lpExe );
   LPWSTR lpWCmd = AnsiToWide( lpCmd );
   ...
   hb_xfree( lpExe );
   hb_xfree( lpCmd );
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Sun Oct 29, 2006 8:05 pm

Pawel,

What code is it there ?

c:\vce\include\datareelce\strutil.h(134) : error C2061: syntax error : identifier 'gxwchar'
c:\vce\include\datareelce\strutil.h(134) : error C2059: syntax error : ';'
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby pawelu » Sun Oct 29, 2006 8:10 pm

Antonio,

Yes, you are right.
WinExec provides method to stop this function above time running limit (I use this function with GPRS connection, in some situation break connection is only way to back to execution program code) ?
What is the method to compile and link my sample code with your change in current FWPPC build ?

Thanks
Pawel
pawelu
 
Posts: 126
Joined: Thu Oct 06, 2005 10:18 pm
Location: Poland

Postby Antonio Linares » Sun Oct 29, 2006 8:13 pm

Pawel,

A simpler solution :-)

Current Harbour (the one used by FWPPC) lets you mix C and C++ code. So you can compile your code with -TP to avoid the errors and simply use this:

extern "C"
{
LPWSTR AnsiToWide( LPSTR );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Pocket PC

Who is online

Users browsing this forum: No registered users and 7 guests