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. A qustion on Dll Call

A qustion on Dll Call

Scheduled Pinned Locked Moved C#
helpquestion
3 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.
  • X Offline
    X Offline
    Xiaoming Qian
    wrote on last edited by
    #1

    Hi everybody.I have problems when calling dll. Here is the Dll function definition(from the vander's document): __int16 __stdcall MW_GetDBRecord(HANDLE icdev, __int16 fsid, __int16 rec_size, char *buf, int *rlen) Input parameters: icdev: device handle fsid: selected table NO. rec_size: a record size space. Output parameters : Buf: return entire record data (you need give buf enough space ); Rlen: length of data . And here is my code: [DllImport("mwhandset")] public static extern Int16 MW_GetDBRecord(IntPtr icdev,Int16 fsid, Int16 rec_size,ref string buff,ref int rlen); ... private void button3_Click(object sender, System.EventArgs e) { ... int rlen = 0; string buff; buff = " ";//the length is enough MW_GetDBRecord(m_icdev,0,16,buff,ref rlen); } When calling MW_GetDBRecord it raise "System.NullReferenceException: Object not set to an instance".I'm sure the function has completed on the device, because rlen=16(the record size) when the exception raised.So I think it is caused by type incompatibility,most likely the buff parameter.What type should I use corresponding to "char *buf"? Or it is caused by any other reason? Can anyone help me? Any idea will be appropriate.

    T 1 Reply Last reply
    0
    • X Xiaoming Qian

      Hi everybody.I have problems when calling dll. Here is the Dll function definition(from the vander's document): __int16 __stdcall MW_GetDBRecord(HANDLE icdev, __int16 fsid, __int16 rec_size, char *buf, int *rlen) Input parameters: icdev: device handle fsid: selected table NO. rec_size: a record size space. Output parameters : Buf: return entire record data (you need give buf enough space ); Rlen: length of data . And here is my code: [DllImport("mwhandset")] public static extern Int16 MW_GetDBRecord(IntPtr icdev,Int16 fsid, Int16 rec_size,ref string buff,ref int rlen); ... private void button3_Click(object sender, System.EventArgs e) { ... int rlen = 0; string buff; buff = " ";//the length is enough MW_GetDBRecord(m_icdev,0,16,buff,ref rlen); } When calling MW_GetDBRecord it raise "System.NullReferenceException: Object not set to an instance".I'm sure the function has completed on the device, because rlen=16(the record size) when the exception raised.So I think it is caused by type incompatibility,most likely the buff parameter.What type should I use corresponding to "char *buf"? Or it is caused by any other reason? Can anyone help me? Any idea will be appropriate.

      T Offline
      T Offline
      Tarakeshwar Reddy
      wrote on last edited by
      #2

      This has to be

      Xiaoming Qian wrote:

      [DllImport("mwhandset")] public static extern Int16 MW_GetDBRecord(IntPtr icdev,Int16 fsid, Int16 rec_size,ref string buff,ref int rlen);

      Like this: public static extern int MW_GetDBRecord(IntPtr icdev, int fsid, int rec_size, [Out] byte[] buf, int bufSize); And this has to be

      Xiaoming Qian wrote:

      MW_GetDBRecord(m_icdev,0,16,buff,ref rlen);

      this

      int size = 256; //what ever you want it to be
      byte[] buf = new byte[size];

      MW_GetDBRecord(m_icdev, 0, 16, buf, size);

      I suggest you read these articles.[^]


      Tarakeshwar Reddy MCP, CCIE Q(R&S) There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi

      X 1 Reply Last reply
      0
      • T Tarakeshwar Reddy

        This has to be

        Xiaoming Qian wrote:

        [DllImport("mwhandset")] public static extern Int16 MW_GetDBRecord(IntPtr icdev,Int16 fsid, Int16 rec_size,ref string buff,ref int rlen);

        Like this: public static extern int MW_GetDBRecord(IntPtr icdev, int fsid, int rec_size, [Out] byte[] buf, int bufSize); And this has to be

        Xiaoming Qian wrote:

        MW_GetDBRecord(m_icdev,0,16,buff,ref rlen);

        this

        int size = 256; //what ever you want it to be
        byte[] buf = new byte[size];

        MW_GetDBRecord(m_icdev, 0, 16, buf, size);

        I suggest you read these articles.[^]


        Tarakeshwar Reddy MCP, CCIE Q(R&S) There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi

        X Offline
        X Offline
        Xiaoming Qian
        wrote on last edited by
        #3

        Thank you, it works. :-D

        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