Results 1 to 5 of 5

Thread: How do I write this VB6 dll call in C#? [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796

    How do I write this VB6 dll call in C#? [RESOLVED]

    How do I call a legacy 32-bit dll from C#?

    The VB6 code would look like this:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function MyFunc Lib "my.dll" _
    4.           (ByVal cmd As String) As Boolean
    5.  
    6. Private Sub Command1_Click()
    7.  
    8.   If MyFunc("abc") Then
    9.     MsgBox "Cool!"
    10.   End If
    11.  
    12. End Sub

    How should that look in C#?

    Thanks!
    Last edited by BrianHawley; Jan 10th, 2004 at 08:58 AM.
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    http://msdn.microsoft.com/library/de...rfExternPG.asp

    Code:
    class SomethingOrOther
    {
        [DllImport("my.Dll")]
        public static extern bool MyFunc(string cmd);
    
        private void btnBlah_Click(object sender, EventArgs e)
        {
            if (MyFunc("abc"))
            {
                // Etc etc
            }
        }
    }
    Last edited by axion_sa; Jan 7th, 2004 at 12:25 PM.

  3. #3

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796
    Many thanks!
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

  4. #4
    New Member
    Join Date
    Jul 2010
    Posts
    2

    Re: How do I write this VB6 dll call in C#? [RESOLVED]

    Please help: I did this example verbatim except for my path statement and I got the following erro:

    Unable to find an entry point named 'MyFunc' in DLL 'c:\MyFunction32\my.Dll'.

    Any ideas ?

  5. #5
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: How do I write this VB6 dll call in C#? [RESOLVED]

    Quote Originally Posted by talktodale View Post
    Please help: I did this example verbatim except for my path statement and I got the following erro:

    Unable to find an entry point named 'MyFunc' in DLL 'c:\MyFunction32\my.Dll'.

    Any ideas ?
    Do you have the code for my.dll?
    The DLLImport directive works with DLL's that have exported functions.

    Quote Originally Posted by msdn
    These attributes explicitly define the DLL's interface to its client, which can be the executable file or another DLL. Declaring functions as dllexport eliminates the need for a module-definition (.DEF) file, at least with respect to the specification of exported functions. Note that dllexport replaces the __export keyword.

    If a class is marked declspec(dllexport), any specializations of class templates in the class hierarchy are implicitly marked as declspec(dllexport). This means templates are explicitly instantiated and its members must be defined.

    dllexport of a C++ function will expose the function with C++ name mangling. If C++ name mangling is not desired, either use a .def file (EXPORTS keyword) or declare the function as extern "C".
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width