VC++ TO PureBasic , Thank

Windows specific forum
Rascal
User
User
Posts: 30
Joined: Mon Sep 17, 2007 11:06 pm

VC++ TO PureBasic , Thank

Post by Rascal »

Code: Select all

/*
  Copyright (c) Microsoft Corporation
  Module Name: upcase.c
*/

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <httpfilt.h>

BOOL WINAPI __stdcall GetFilterVersion(HTTP_FILTER_VERSION *pVer)
{
  /* Specify the types and order of notification */

  pVer->dwFlags = (SF_NOTIFY_NONSECURE_PORT | SF_NOTIFY_URL_MAP |  SF_NOTIFY_SEND_RAW_DATA | SF_NOTIFY_ORDER_DEFAULT);

  pVer->dwFilterVersion = HTTP_FILTER_REVISION;

  strcpy(pVer->lpszFilterDesc, "Upper case conversion filter, Version 1.0");

  return TRUE;
}

DWORD WINAPI __stdcall HttpFilterProc(HTTP_FILTER_CONTEXT *pfc, DWORD NotificationType, VOID *pvData)
{
  CHAR *pchIn, *pPhysPath;
  DWORD  cbBuffer,  cbtemp;
  PHTTP_FILTER_URL_MAP pURLMap;
  PHTTP_FILTER_RAW_DATA  pRawData;

  switch (NotificationType)  {

    case SF_NOTIFY_URL_MAP :

      /* Check the URL for a subdirectory in the form of /UC/ or /uc/ */

      pURLMap  =  (PHTTP_FILTER_URL_MAP)pvData;

      pPhysPath  =  pURLMap->pszPhysicalPath;

      pfc->pFilterContext  =  0;

      for ( ; *pPhysPath; pPhysPath++) 
      {
        /* Ensure that there are at least 4 characters (checking for "\UC\") left in the URL before checking */

        if (strlen(pPhysPath) > 3) 
        {
          if (*pPhysPath == '\\' && (*(pPhysPath + 1) == 'u' || *(pPhysPath + 1) == 'U') && (*(pPhysPath + 2) == 'c' || *(pPhysPath + 2) == 'C') && *(pPhysPath + 3) ==  '\\')
          {
            /* Now that we've found it, remove it by collapsing everything down */

            for ( ; *(pPhysPath + 3) ; pPhysPath++)
              *pPhysPath = *(pPhysPath + 3);

            /* NULL terminate the string */

            *pPhysPath = '\0'; 

            /* And set the flag to let the SF_NOTIFY_SEND_RAW_DATA handler know to uppercase the content */

            pfc->pFilterContext  =  (VOID  *)1;

            /* Break us out of the loop - note that this will only find the first instance of /UC/ in the URL */

            break;
          }
        }
      }

      break;

    case SF_NOTIFY_SEND_RAW_DATA :

      if (pfc->pFilterContext)
      {
        pRawData = (PHTTP_FILTER_RAW_DATA)pvData;

        pchIn  =  (BYTE  *)pRawData->pvInData;

        cbBuffer = 0;

        if (pfc->pFilterContext  == (VOID *)1)
        {
          /* 
          As this is the first block, scan through it until 2 CRLFs are seen, to pass
          all of the headers.
          */

          for ( ; cbBuffer < pRawData->cbInData - 2; cbBuffer++)
          {
            if (pchIn[cbBuffer]  == '\n' && pchIn[cbBuffer + 2]  == '\n')
            {
              cbBuffer += 3;

              break;
            }

            cbBuffer++;
          }

          for (cbtemp = 0; cbtemp < (cbBuffer - 3); cbtemp++) 
          {
            if (pchIn[cbtemp] == '/' && pchIn[cbtemp + 1] == 'h' && pchIn[cbtemp + 2] == 't' && pchIn[cbtemp + 3] == 'm')
            {
              pfc->pFilterContext  =  (VOID  *)2;

              break;
            }
          }

          if (cbtemp ==  cbBuffer)
            pfc->pFilterContext  =  0; /* not an  html file */
        }

        /* Now uppercase everything */

        if (pfc->pFilterContext)
          for ( ; cbBuffer < pRawData->cbInData; cbBuffer++)
            pchIn[cbBuffer] = (pchIn[cbBuffer] >= 'a' && pchIn[cbBuffer] <= 'z') ? (pchIn[cbBuffer] - 'a' + 'A') : pchIn[cbBuffer];
      }

      break;

    default :

      break;        
  }

  return SF_STATUS_REQ_NEXT_NOTIFICATION;
}

inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post by inc. »

In such a case I would just compile the code in VC++ as lib, then you can import these functions/symbols out of the VC++ resulted obj's using PB's "Import" Command.
Check out OOP support for PB here!
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Code: Select all

pchIn[cbBuffer] = (pchIn[cbBuffer] >= 'a' && pchIn[cbBuffer] <= 'z') ? (pchIn[cbBuffer] - 'a' + 'A') : pchIn[cbBuffer]; 
Very nice :)
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post by inc. »

Not very, but its C's alternative to the If/Else approach.

In PB:

Code: Select all

If PeekB(pchIn + cbBuffer) >= 'a' AND PeekB(cbBuffer) <= 'z'
  PokeB(pchIn+cbBuffer, PeekB(pchIn+cbBuffer) - 'a' + 'A')
Endif
Check out OOP support for PB here!
Rascal
User
User
Posts: 30
Joined: Mon Sep 17, 2007 11:06 pm

Post by Rascal »

I want Code PureBasic
Fred
Administrator
Administrator
Posts: 18360
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

You don't want anything. The forum is not a code convertor. So be gentle and try to do the conversion by yourself and if you have a problem, ask.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Rascal wrote:I want Code PureBasic
Bahahahahahaha! Image
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Looks like a post by MysticBoy again. Just code with no explanation, and
expecting a conversion to be there when he wakes up. MysticBoy's MO.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

almost every post I saw MysticBoy make concerned converting some code or other whos purpose was very 'virus' or 'trojan' like. Is this more of the same form him?
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

I want code Purebasic too.
I want a program that downloads all the creditcard numbers in the world and automatically puts the money into my account. It must also automatically buy me the latest flatscreen tv and it must be delivered to my door. And if I am asleep, the door must open so the delivery people can install the new tv for me so it is ready when I wake up. Also, when I get something new, it must make me coffee so I am ready to go when I wake up. Any takers?
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Post by Foz »

yup, here we go:

Code: Select all

Procedure.b UltimateFunctionForLifeTheUniverseAndEverything()
  ProcedureReturn 42
EndProcedure
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Thanks Foz. It works great. Only thing is, my DVD player is on the AV2 channel, NOT AV1. Please fix or I'll have a tantrum :lol:
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Post by Foz »

hmmm... tricky... very tricky...

Current methods cannot do such a task... therefore:

Code: Select all

Procedure FixForUltimateFunctionForLifeTheUniverseAndEverything()
  Define result = 6*9
  If result <> UltimateFunctionForLifeTheUniverseAndEverything()
    BadThingsHappen()
    Cry()
    SelfDestruct()
    Explode()
    If WindowsOS
      BSOD()
    Else
      KernalPanic()
    EndIf
  Else
    ProcedureReturn result
  EndIf
EndProcedure
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Post by citystate »

inc. wrote:Not very, but its C's alternative to the If/Else approach.

In PB:

Code: Select all

If PeekB(pchIn + cbBuffer) >= 'a' AND PeekB(cbBuffer) <= 'z'
  PokeB(pchIn+cbBuffer, PeekB(pchIn+cbBuffer) - 'a' + 'A')
Endif
what about:

Code: Select all

PokeS(pchIn, UCase(PeekS(pchIn)))
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Post by Pantcho!! »

And i want PP
:lol:
Post Reply