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. .NET (Core and Framework)
  4. calling unmanged code from j#

calling unmanged code from j#

Scheduled Pinned Locked Moved .NET (Core and Framework)
c++question
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.
  • G Offline
    G Offline
    godzooky
    wrote on last edited by
    #1

    i have an unmanaged dll that exports a function that takes a TCHAR* parameter. i need to call this function from j#. in my j# file, i tried to set the marshal attribute like so, public static native void testStringFunction(/** @attribute MarshalAs(UnmanagedType.LPTStr)*/String s); when i call that function, my string is not marshaled to a TCHAR*. i tried all the different string types in the UnmanagedType enumeration. anyone have any ideas?? thanks.

    H 1 Reply Last reply
    0
    • G godzooky

      i have an unmanaged dll that exports a function that takes a TCHAR* parameter. i need to call this function from j#. in my j# file, i tried to set the marshal attribute like so, public static native void testStringFunction(/** @attribute MarshalAs(UnmanagedType.LPTStr)*/String s); when i call that function, my string is not marshaled to a TCHAR*. i tried all the different string types in the UnmanagedType enumeration. anyone have any ideas?? thanks.

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

      Did you attribute it with the DllImportAttribute, specifying the right native DLL? You should also specify in that attribute CharSet=CharSet.Auto. Other than that, your code looks fine.

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      G 1 Reply Last reply
      0
      • H Heath Stewart

        Did you attribute it with the DllImportAttribute, specifying the right native DLL? You should also specify in that attribute CharSet=CharSet.Auto. Other than that, your code looks fine.

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        G Offline
        G Offline
        godzooky
        wrote on last edited by
        #3

        i figured out my problem. i accidently installed VS .NET 2002. i upgraded to 2003 and it works fine.

        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