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
  1. Home
  2. General Programming
  3. C#
  4. DllImport and parameters

DllImport and parameters

Scheduled Pinned Locked Moved C#
jsonquestion
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.
  • P Offline
    P Offline
    paulb
    wrote on last edited by
    #1

    What are the rules for specifying the parameter types for Win API functions using DllImport? E.g. this thing... DWORD GetPrivateProfileString( LPCTSTR lpAppName, // section name LPCTSTR lpKeyName, // key name LPCTSTR lpDefault, // default string LPTSTR lpReturnedString, // destination buffer DWORD nSize, // size of destination buffer LPCTSTR lpFileName // initialization file name ); How would I import that? would this be correct... [DllImport("kernel32.dll")] static extern int GetPrivateProfileString(string section, string key, string def, string val, int size, string file);

    J 1 Reply Last reply
    0
    • P paulb

      What are the rules for specifying the parameter types for Win API functions using DllImport? E.g. this thing... DWORD GetPrivateProfileString( LPCTSTR lpAppName, // section name LPCTSTR lpKeyName, // key name LPCTSTR lpDefault, // default string LPTSTR lpReturnedString, // destination buffer DWORD nSize, // size of destination buffer LPCTSTR lpFileName // initialization file name ); How would I import that? would this be correct... [DllImport("kernel32.dll")] static extern int GetPrivateProfileString(string section, string key, string def, string val, int size, string file);

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      There are two different versions of GetPrivateProfileString, one for ANSI strings and another for wide/Unicode strings; so you'll need to specify that. Your destination buffer should also be a StringBuilder rather than a string. There is a utility posted on GotDotNet that will generate the correct DllImport statements for you. You need a copy of the win32api.txt from VB6 though. HTH, James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978

      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