Vb6 Convert

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Hunt

    Vb6 Convert

    Hi
    Can you help me with converting a VB6 Declare Function construct to C#
    systax. I think it is in the form of

    [DLLImport ("A.DLL")]
    public extrn void someFunction(.. ...);

    But I don't see the association between the 2 statements. Can someone
    explain ?

    THanks


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Vb6 Convert

    Phil,

    Well, the DllImport attribute tells the CLR what the name of the DLL is
    to load to find the function in (as well as other information, like the .
    The CLR will then use function information to figure out the signature of
    the function and load it from the dll, and subsequently call it.

    The "extern" keyword here, combined with the attribute indicates that
    the function is found in an unmanaged DLL (there should be a static keyword
    here as well).


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Phil Hunt" <aaa@aaa.comwro te in message
    news:%23r$DHm2P JHA.4424@TK2MSF TNGP06.phx.gbl. ..
    Hi
    Can you help me with converting a VB6 Declare Function construct to C#
    systax. I think it is in the form of
    >
    [DLLImport ("A.DLL")]
    public extrn void someFunction(.. ...);
    >
    But I don't see the association between the 2 statements. Can someone
    explain ?
    >
    THanks
    >

    Comment

    • Phil Hunt

      #3
      Re: Vb6 Convert

      The dll i have that has many entry point. It seems like I have to repeat the
      Import statement everytime I declare a different function. Is that a short
      hand for that. Also in VB6 the Declare stmt associate the fucntion with the
      dll. Can I do that in this contruct ?

      Thanks again


      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in
      message news:OUdnZz2PJH A.3932@TK2MSFTN GP02.phx.gbl...
      Phil,
      >
      Well, the DllImport attribute tells the CLR what the name of the DLL is
      to load to find the function in (as well as other information, like the .
      The CLR will then use function information to figure out the signature of
      the function and load it from the dll, and subsequently call it.
      >
      The "extern" keyword here, combined with the attribute indicates that
      the function is found in an unmanaged DLL (there should be a static
      keyword here as well).
      >
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m
      >
      "Phil Hunt" <aaa@aaa.comwro te in message
      news:%23r$DHm2P JHA.4424@TK2MSF TNGP06.phx.gbl. ..
      >Hi
      >Can you help me with converting a VB6 Declare Function construct to C#
      >systax. I think it is in the form of
      >>
      >[DLLImport ("A.DLL")]
      >public extrn void someFunction(.. ...);
      >>
      >But I don't see the association between the 2 statements. Can someone
      >explain ?
      >>
      >THanks
      >>
      >
      >

      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: Vb6 Convert

        Phil,

        Yes, you are right, you have to make a new declaration for each function
        that you want to use through the P/Invoke layer.

        There is no shorthand for that, AFAIK.

        The DllImport attribute is what associates the function declaration with
        the DLL that it is located in. You have to repeat this for every
        declaration as well.


        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m

        "Phil Hunt" <aaa@aaa.comwro te in message
        news:eHMj9O3PJH A.3932@TK2MSFTN GP02.phx.gbl...
        The dll i have that has many entry point. It seems like I have to repeat
        the Import statement everytime I declare a different function. Is that a
        short hand for that. Also in VB6 the Declare stmt associate the fucntion
        with the dll. Can I do that in this contruct ?
        >
        Thanks again
        >
        >
        "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote
        in message news:OUdnZz2PJH A.3932@TK2MSFTN GP02.phx.gbl...
        >Phil,
        >>
        > Well, the DllImport attribute tells the CLR what the name of the DLL
        >is to load to find the function in (as well as other information, like
        >the . The CLR will then use function information to figure out the
        >signature of the function and load it from the dll, and subsequently call
        >it.
        >>
        > The "extern" keyword here, combined with the attribute indicates that
        >the function is found in an unmanaged DLL (there should be a static
        >keyword here as well).
        >>
        >>
        >--
        > - Nicholas Paldino [.NET/C# MVP]
        > - mvp@spam.guard. caspershouse.co m
        >>
        >"Phil Hunt" <aaa@aaa.comwro te in message
        >news:%23r$DHm2 PJHA.4424@TK2MS FTNGP06.phx.gbl ...
        >>Hi
        >>Can you help me with converting a VB6 Declare Function construct to C#
        >>systax. I think it is in the form of
        >>>
        >>[DLLImport ("A.DLL")]
        >>public extrn void someFunction(.. ...);
        >>>
        >>But I don't see the association between the 2 statements. Can someone
        >>explain ?
        >>>
        >>THanks
        >>>
        >>
        >>
        >
        >

        Comment

        • Phil Hunt

          #5
          Re: Vb6 Convert

          Thanks for your help.

          "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in
          message news:udZi6T3PJH A.4224@TK2MSFTN GP04.phx.gbl...
          Phil,
          >
          Yes, you are right, you have to make a new declaration for each
          function that you want to use through the P/Invoke layer.
          >
          There is no shorthand for that, AFAIK.
          >
          The DllImport attribute is what associates the function declaration
          with the DLL that it is located in. You have to repeat this for every
          declaration as well.
          >
          >
          --
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard. caspershouse.co m
          >
          "Phil Hunt" <aaa@aaa.comwro te in message
          news:eHMj9O3PJH A.3932@TK2MSFTN GP02.phx.gbl...
          >The dll i have that has many entry point. It seems like I have to repeat
          >the Import statement everytime I declare a different function. Is that a
          >short hand for that. Also in VB6 the Declare stmt associate the fucntion
          >with the dll. Can I do that in this contruct ?
          >>
          >Thanks again
          >>
          >>
          >"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote
          >in message news:OUdnZz2PJH A.3932@TK2MSFTN GP02.phx.gbl...
          >>Phil,
          >>>
          >> Well, the DllImport attribute tells the CLR what the name of the DLL
          >>is to load to find the function in (as well as other information, like
          >>the . The CLR will then use function information to figure out the
          >>signature of the function and load it from the dll, and subsequently
          >>call it.
          >>>
          >> The "extern" keyword here, combined with the attribute indicates that
          >>the function is found in an unmanaged DLL (there should be a static
          >>keyword here as well).
          >>>
          >>>
          >>--
          >> - Nicholas Paldino [.NET/C# MVP]
          >> - mvp@spam.guard. caspershouse.co m
          >>>
          >>"Phil Hunt" <aaa@aaa.comwro te in message
          >>news:%23r$DHm 2PJHA.4424@TK2M SFTNGP06.phx.gb l...
          >>>Hi
          >>>Can you help me with converting a VB6 Declare Function construct to C#
          >>>systax. I think it is in the form of
          >>>>
          >>>[DLLImport ("A.DLL")]
          >>>public extrn void someFunction(.. ...);
          >>>>
          >>>But I don't see the association between the 2 statements. Can someone
          >>>explain ?
          >>>>
          >>>THanks
          >>>>
          >>>
          >>>
          >>
          >>
          >
          >

          Comment

          Working...