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. from VC6 dll

from VC6 dll

Scheduled Pinned Locked Moved C#
tutorialquestion
5 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.
  • Y Offline
    Y Offline
    yyf
    wrote on last edited by
    #1

    Hi, everyone 1. When I call a function imported from a VC6 dll, it returns 42949672970 when it is supposed to return -1. Anyone knows why? 2. There's another function in this VC6 dll like this loginDlg(LPCTSTR Name, long NameLength). This function will return the login name by the first parameter, 2nd parameter is tell the function how long the buffer is. How to import and use this kind of functions properly? Thanks in advance.

    H 1 Reply Last reply
    0
    • Y yyf

      Hi, everyone 1. When I call a function imported from a VC6 dll, it returns 42949672970 when it is supposed to return -1. Anyone knows why? 2. There's another function in this VC6 dll like this loginDlg(LPCTSTR Name, long NameLength). This function will return the login name by the first parameter, 2nd parameter is tell the function how long the buffer is. How to import and use this kind of functions properly? Thanks in advance.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Looks like the address of a return value is being returned. How are you declaring the native function to be P/Invoked?

      Microsoft MVP, Visual C# My Articles

      Y 1 Reply Last reply
      0
      • H Heath Stewart

        Looks like the address of a return value is being returned. How are you declaring the native function to be P/Invoked?

        Microsoft MVP, Visual C# My Articles

        Y Offline
        Y Offline
        yyf
        wrote on last edited by
        #3

        Here is how the function declare in the VC6 dll head file #ifndef LONG typedef long LONG; /* 32 bit */ #endif LONG _stdcall SelectChildProjects ( LONG lProjectId /* i Number of parent project */ ); Here is how I declare the function in my .Net code [DllImport("dcli.dll", EntryPoint="SelectChildProjects")] public static extern long SelectChildProjects(long lProjectId); Thanks.

        H 1 Reply Last reply
        0
        • Y yyf

          Here is how the function declare in the VC6 dll head file #ifndef LONG typedef long LONG; /* 32 bit */ #endif LONG _stdcall SelectChildProjects ( LONG lProjectId /* i Number of parent project */ ); Here is how I declare the function in my .Net code [DllImport("dcli.dll", EntryPoint="SelectChildProjects")] public static extern long SelectChildProjects(long lProjectId); Thanks.

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          A LONG (long) in C++ is a 32-bit integer. A long (Int64) is a 64-bit integer. You're marshaling is all wrong which might explain why you're getting extra data from overflow. You should declare it as:

          [DllImport("dcli.dll")]
          public static extern int SelectChildProjects(int lProjectId);

          Notice I also dropped the EntryPoint property, which you only need in cases where your declared method differs in name from the entry point exported by the native DLL.

          Microsoft MVP, Visual C# My Articles

          Y 1 Reply Last reply
          0
          • H Heath Stewart

            A LONG (long) in C++ is a 32-bit integer. A long (Int64) is a 64-bit integer. You're marshaling is all wrong which might explain why you're getting extra data from overflow. You should declare it as:

            [DllImport("dcli.dll")]
            public static extern int SelectChildProjects(int lProjectId);

            Notice I also dropped the EntryPoint property, which you only need in cases where your declared method differs in name from the entry point exported by the native DLL.

            Microsoft MVP, Visual C# My Articles

            Y Offline
            Y Offline
            yyf
            wrote on last edited by
            #5

            Thank you very much! It works prefectly now.

            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