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. Managed C++/CLI
  4. System::String ^ to LPCVOID conversion? [modified]

System::String ^ to LPCVOID conversion? [modified]

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestionwinforms
2 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.
  • M Offline
    M Offline
    Mattzimmerer
    wrote on last edited by
    #1

    Im trying to use WriteFile() to communicate with a driver, the information its sending is to be text from a Windows Forms textbox. I've tried so much to get it to work properly but it only seems to work if I do the following for WriteFile(): WriteFile(hFile, "this is the only way it works", sizeof("this is the only way it works");, &dwReturn, NULL); Im pretty lost and I would appreciate any help! Heres what my code looks like:

    System::String ^str = this->Address->Text; //ANOTHER QUESTION.. WHATS THE ^ mean before str? Or where can I read about this operator?
    LPCVOID lpBuffer = str;
    /*BOOL WINAPI WriteFile(
    __in HANDLE hFile,
    __in LPCVOID lpBuffer,
    __in DWORD nNumberOfBytesToWrite,
    __out_opt LPDWORD lpNumberOfBytesWritten,
    __inout_opt LPOVERLAPPED lpOverlapped );*/
    WriteFile(hFile, lpBuffer, sizeof(lpBuffer), &dwReturn, NULL);
    CloseHandle(hFile);

    and the compiler output: 1>c:\users\matt_zimmerer_testos\desktop\zmdalpha1.0\gui\zmdinterface\Form1.h(170) : error C2440: 'initializing' : cannot convert from 'System::String ^' to 'LPCVOID' EDIT: minor grammar error fixed

    modified on Saturday, January 2, 2010 5:06 PM

    L 1 Reply Last reply
    0
    • M Mattzimmerer

      Im trying to use WriteFile() to communicate with a driver, the information its sending is to be text from a Windows Forms textbox. I've tried so much to get it to work properly but it only seems to work if I do the following for WriteFile(): WriteFile(hFile, "this is the only way it works", sizeof("this is the only way it works");, &dwReturn, NULL); Im pretty lost and I would appreciate any help! Heres what my code looks like:

      System::String ^str = this->Address->Text; //ANOTHER QUESTION.. WHATS THE ^ mean before str? Or where can I read about this operator?
      LPCVOID lpBuffer = str;
      /*BOOL WINAPI WriteFile(
      __in HANDLE hFile,
      __in LPCVOID lpBuffer,
      __in DWORD nNumberOfBytesToWrite,
      __out_opt LPDWORD lpNumberOfBytesWritten,
      __inout_opt LPOVERLAPPED lpOverlapped );*/
      WriteFile(hFile, lpBuffer, sizeof(lpBuffer), &dwReturn, NULL);
      CloseHandle(hFile);

      and the compiler output: 1>c:\users\matt_zimmerer_testos\desktop\zmdalpha1.0\gui\zmdinterface\Form1.h(170) : error C2440: 'initializing' : cannot convert from 'System::String ^' to 'LPCVOID' EDIT: minor grammar error fixed

      modified on Saturday, January 2, 2010 5:06 PM

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      System::String is a managed type and needs to be converted to a character array before you can cast it to a simple pointer. Take a look at the System::String[^] class, for more information.

      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