Calling Dll function from VB
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Calling Dll function from VB

  1. #1
    Join Date
    Sep 2001
    Location
    Hong Kong
    Posts
    63

    Post Calling Dll function from VB

    Hi All,

    I have created a simple DLL with Win32 Application Extension Wizard. I have a a couple of function that are to called from a VB project. Thus I have set the calling convension to __stdcall in the Project Settings. In VB I have used the following syntax:

    Code:
    Private Declare Function fTest Lib "<Path of Dll>" Alias "fnTest" () as Long
    
    Private Sub Command1_Click()
       Dim r as Long
       r = fTest()
    End Sub
    I am receving a error message saying
    Code:
    Error: 453 Can't Find Dll Entry Point for fnTest
    I have also observed that it is DllMain call is successfull.

    Please let me know what is problem in the code. The code is below:

    Header File:
    Code:
    #ifdef TEST_EXPORTS
    #define TEST_API __declspec(dllexport)
    #else
    #define TEST_API __declspec(dllimport)
    #endif
    
    // This class is exported from the test.dll
    #if defined(__cplusplus)
    extern "C"{
    #endif
    
    TEST_API int fnTest(void);
    
    #if defined(__cplusplus)
    }
    #endif
    Implementation File:
    Code:
    #include "stdafx.h"
    #include "test.h"
    
    BOOL APIENTRY DllMain( HANDLE hModule, 
                           DWORD  ul_reason_for_call, 
                           LPVOID lpReserved
    					 )
    {
    	MessageBox(NULL, "From Dll Main", "From Test Dll", MB_ICONASTERISK);
        switch (ul_reason_for_call)
    	{
    		case DLL_PROCESS_ATTACH:
    		case DLL_THREAD_ATTACH:
    		case DLL_THREAD_DETACH:
    		case DLL_PROCESS_DETACH:
    			break;
        }
        return TRUE;
    }
    
    // This is an example of an exported function.
    TEST_API int fnTest(void)
    {
    	MessageBox(NULL, "Success!! Test Message", "From Test Dll", MB_ICONASTERISK);
    	return 42;
    }
    Thanks In Advance

    regards
    rcs

  2. #2
    Join Date
    Apr 2002
    Location
    DELHI(India)
    Posts
    51
    hi...,

    If Win32 application is not your requirement.then I can help you for the above purpose by creating DLL with ATL COM and using it's functions in VB.
    if that helps you then please let me know.

    Regards,
    Vimal Naik

  3. #3
    Join Date
    Sep 2001
    Location
    Hong Kong
    Posts
    63
    Thanks vimal naik but I do not want to use ATL COM components, because, the Dll will be used in a Programming Tool called MapBasic, which has the syntax similar to VB. One cannot use COM Components from MapBasic.

    So Win32 application is my requirement.

    Thanks In advance

    regards
    rcs

  4. #4
    Join Date
    Mar 2002
    Location
    Izhevsk, Udmurtia, Russia
    Posts
    930
    I think you should use the DEF-file and specify your function there.
    Code:
    EXPORTS
    	DllMain	@1	PRIVATE
    	fnTest	@2	PRIVATE
    Otherwise you must use something like "fnTest@8" or "_fnTest@8" or "_fnTest". I do not know precisely.
    Last edited by Vi2; May 23rd, 2002 at 07:15 AM.
    With best wishes,
    Vita
    -----------------------
    Russian Software Development Network -- http://www.rsdn.ru

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center