Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. COM
  4. LPSTR and LPBYTE passing to a dll

LPSTR and LPBYTE passing to a dll

Scheduled Pinned Locked Moved COM
questionc++comhardwaredata-structures
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paul_591
    wrote on last edited by
    #1

    Guys, I am an accomplished embedded coder, but not very adept with windows programming or COM. However, I have a quick command line program to write to make use of a seed2key dll. The dlls prototype is.. API seed2key(char *seed, BYTE *key). I know this because I have the source code for it. However, when trying to use the seed2key function in a C++ console app, the compiler thinks that the parameters should be of type LPSTR and LPBYTE respectively. Unfortunately I have no idea what these are. I have a 16 byte array carrying the seed, that i need to pass to this function. How do i create an LPSTR from that? Does anyone have any idea what parameters it is actually after, and can provide me with a way to do so? Many Thanks to anyone who can help. Paul.

    J 1 Reply Last reply
    0
    • P Paul_591

      Guys, I am an accomplished embedded coder, but not very adept with windows programming or COM. However, I have a quick command line program to write to make use of a seed2key dll. The dlls prototype is.. API seed2key(char *seed, BYTE *key). I know this because I have the source code for it. However, when trying to use the seed2key function in a C++ console app, the compiler thinks that the parameters should be of type LPSTR and LPBYTE respectively. Unfortunately I have no idea what these are. I have a 16 byte array carrying the seed, that i need to pass to this function. How do i create an LPSTR from that? Does anyone have any idea what parameters it is actually after, and can provide me with a way to do so? Many Thanks to anyone who can help. Paul.

      J Offline
      J Offline
      JonEngle
      wrote on last edited by
      #2

      LPSTR = long pointer to string, ie char * LPBYTE = long pointer to byte, ie BYTE * -> ie unsigned char * Do you have the code snippet that's failing to build?

      P 1 Reply Last reply
      0
      • J JonEngle

        LPSTR = long pointer to string, ie char * LPBYTE = long pointer to byte, ie BYTE * -> ie unsigned char * Do you have the code snippet that's failing to build?

        P Offline
        P Offline
        Paul_591
        wrote on last edited by
        #3

        Thanks for that! I couldnt find that information anywhere on the web! The code snippet is below. It is VERY rough as I am hacking around to get a solution. :-) int main() { BOOL procReturn = 0; HINSTANCE dllHandle = NULL; KWP_COMPUTEKEYFROMSEED pSeedAndKeyFunc = NULL; dllHandle = LoadLibrary("seed_inv.dll"); if (!dllHandle) { cout<< "Failed to Load dll" << endl; } else { cout<< "DLL loaded OK" << endl; } if (dllHandle) pSeedAndKeyFunc = (KWP_COMPUTEKEYFROMSEED) GetProcAddress(dllHandle, "seed2key"); if (!pSeedAndKeyFunc) { cout<< "ProcAddress Failed"<

        J 1 Reply Last reply
        0
        • P Paul_591

          Thanks for that! I couldnt find that information anywhere on the web! The code snippet is below. It is VERY rough as I am hacking around to get a solution. :-) int main() { BOOL procReturn = 0; HINSTANCE dllHandle = NULL; KWP_COMPUTEKEYFROMSEED pSeedAndKeyFunc = NULL; dllHandle = LoadLibrary("seed_inv.dll"); if (!dllHandle) { cout<< "Failed to Load dll" << endl; } else { cout<< "DLL loaded OK" << endl; } if (dllHandle) pSeedAndKeyFunc = (KWP_COMPUTEKEYFROMSEED) GetProcAddress(dllHandle, "seed2key"); if (!pSeedAndKeyFunc) { cout<< "ProcAddress Failed"<

          J Offline
          J Offline
          JonEngle
          wrote on last edited by
          #4

          This should work: BYTE seed[16] = {0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf,0x00}; status = (*pSeedAndKeyFunc)((LPSTR)seed,key); it's probably looking for the null terminator on the string.

          P 1 Reply Last reply
          0
          • J JonEngle

            This should work: BYTE seed[16] = {0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf,0x00}; status = (*pSeedAndKeyFunc)((LPSTR)seed,key); it's probably looking for the null terminator on the string.

            P Offline
            P Offline
            Paul_591
            wrote on last edited by
            #5

            Fantastic. That seems to work a treat. However, on the inside of the dll, the first function is this.. API seed2key (char *param, BYTE *key) { BYTE seed[16]; DWORD i, retLen, seedLen; BYTE *scanPtr; i = 0; scanPtr = strtok(param, " \t\n"); while (scanPtr && i < 16) { seed[i] = atoi(scanPtr); scanPtr = strtok(NULL, " \t\n"); i++; } seedLen = i; seedToKey (seed, seedLen, key, &retLen); return (retLen); } the while loop iterates once through correctly, but on the second time the string tokenizer returns 0x0000000 into scanPtr. When you hover over it in VS, the tooltip says. [scanPtr = 0x00000000 ]. The above section of code seems to suggest that it is actually requiring a string with the delimeters " ", tab and newline. Rather confusing - although seemingly a different issue, any ideas? Thanks for the previous posts! Paul.

            J 1 Reply Last reply
            0
            • P Paul_591

              Fantastic. That seems to work a treat. However, on the inside of the dll, the first function is this.. API seed2key (char *param, BYTE *key) { BYTE seed[16]; DWORD i, retLen, seedLen; BYTE *scanPtr; i = 0; scanPtr = strtok(param, " \t\n"); while (scanPtr && i < 16) { seed[i] = atoi(scanPtr); scanPtr = strtok(NULL, " \t\n"); i++; } seedLen = i; seedToKey (seed, seedLen, key, &retLen); return (retLen); } the while loop iterates once through correctly, but on the second time the string tokenizer returns 0x0000000 into scanPtr. When you hover over it in VS, the tooltip says. [scanPtr = 0x00000000 ]. The above section of code seems to suggest that it is actually requiring a string with the delimeters " ", tab and newline. Rather confusing - although seemingly a different issue, any ideas? Thanks for the previous posts! Paul.

              J Offline
              J Offline
              JonEngle
              wrote on last edited by
              #6

              I'd see if the seedToKey function their calling is exported, it seems like a safer function to use. Otherwise, I'd probably change this: BYTE seed[16] = {0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf,0x00}; to char seed[] = {0x1,'\n'...,'\n',0xf,0x00}; You can also eliminate the cast that way.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups