mfc >> GetProcAddress giving problems in Explicit linking

by Manoj Pandole » Mon, 24 Nov 2003 13:21:41 GMT

Hi,

I have made a dll in visual basic and am trying to
explicitly link to this dll in a Visual C++ client
application, but although i am able to load this dll, i am
unable to get the pointer to one of the function in this
dll using GetProcAddress. Is it a problem with the
datatypes that i have used to declare the function pointer
in VC++ or is it some other problem, please help me out.
Precisly this is how the exported function looks in VB

Public Function RunShow(strFileName As String,
strArrOfInputParams As Variant, strArrOfOuputParams As
Variant) As Boolean


and this is the function pointer i am using in VC++,

typedef bool (CALLBACK* LPRUNSHOW) (CString, CStringArray,
CStringArray);


Regards,
Manoj Pandole




mfc >> GetProcAddress giving problems in Explicit linking

by Doug Harrison [MVP] » Mon, 24 Nov 2003 13:47:08 GMT






That's not gonna work. VB's "String" type is I believe automation's BSTR,
and that's not the same as VC's CString. Nor is CStringArray compatible with
VARIANT arrays.

According to this message, VB doesn't support exporting functions that way:

http://groups.google.com/groups?selm=OO1NzUspCHA.2472 %40TK2MSFTNGP12

However, if you use VB to create an ActiveX DLL which implements a COM class
which provides the function, you can use it fairly easily through VC's
#import directive and compiler COM support.

If you don't get a definitive answer from an actual VB user, try one of the
microsoft.public.vb groups. :)

--
Doug Harrison
Microsoft MVP - Visual C++



mfc >> GetProcAddress giving problems in Explicit linking

by Manoj Pandole » Mon, 24 Nov 2003 16:49:51 GMT



am
pointer
CStringArray,
automation's BSTR,
CStringArray compatible with
functions that way:
40TK2MSFTNGP12
implements a COM class
through VC's
user, try one of the

Hi again,

I have made an ActiveX DLL in Visual Basic and now i using
#import directive in VC++, but again the results are same,
can anyone their provide a reference to a article on how
to use an #import directive in a case like this. Or can
anyone just provide me with a link to an example for this
anywhere in MSDN.

Regards,
Manoj Pandole


GetProcAddress giving problems in Explicit linking

by Doug Harrison [MVP] » Tue, 25 Nov 2003 01:50:55 GMT





You have to define a COM interface which includes the function, and
implement that interface in a coclass. (For all I know, VB may simplify this
somewhat.) You'll have to register your COM server in the registry and all
that good stuff, and then you can create objects of the coclass in your C++
app. When you #import, you'll have COM smart pointers something like
MyCoClassPtr and MyInterfacePtr, and you can create an object of the coclass
and obtain an interface pointer from it very easily. It is through this
interface pointer that you can finally call your function. For more, look up
_com_ptr_t, #import, etc.

--
Doug Harrison
Microsoft MVP - Visual C++


Similar Threads

1. Explicit link to DLL, problem in BCB but not in MSVC

2. GetProcaddress returns null but GetLastError indicate no problem

3. yet another GetProcAddress() problem

Trying to get the address of a test method and I'm getting NULL.  I have
created a map file and everything looks correct:
<snip>
Exports
  ordinal    name
        1    ?GetNumber@@YAHXZ (int __cdecl GetNumber(void))
</snip>

In the host DLL, I'm importing with this code:
<snip>
typedef int (CALLBACK* LPFNDLLFUNC1)(void);
 HINSTANCE  hDLL;           // Handle to DLL
 LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer

 hDLL =
LoadLibrary("Z:\\M3\\Code\\MAX_Plugins\\InFluFluIO\\Debug\\InFluFluIO.dll");
 if (hDLL != NULL){
  lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,
   "GetNumber");
  if (!lpfnDllFunc1){
   // handle the error
   ::MessageBox(0, "Failed loading InFluFluIO dll", "some tools may not work
correctly", MB_OK|MB_ICONWARNING);

   FreeLibrary(hDLL);
   return -1;
  }
  else{
   // call the function
   result = lpfnDllFunc1();
   FreeLibrary(hDLL);
  }
 }
</snip>

Even though the map file shows me the name, I have tried adding the "_"
before the name.  I get NULL everytime.  Anyone have any ideas?

Any help appreciated,
Steve Klett


4. Problem "GetProcAddress" in Win98.

5. Is __declspec(DLLexport) neccessay with explicit linking?

Hello

I have created a Win32 dll but i am not exporting
any functions by using __declspec(DLLexport).Now from
another application i want to use these functions.Can i do explicit
linking to the dll by doing  a)load the library b)getting the function address
Do we really need to do __declspec(DLLexport) for using that dll for
explicit linking

Thanks in advance
Tauseef

6. How to explicit link a dynamic class library?

7. Calling a static function from a class member method is giving linking errors

Hi Guys,

Maybe this is silly thing to ask but I have a static function declared

static void Foo(int a);

defined in Foo.cpp

and a member method which calls Foo

extern void foo(int a);
void A::Test
{
  int a = 0;
  foo(a);
}

I get linkage errors - 'un-resolved external symbol'. When I change
Foo to non-static, it works. Any ideas?

8. Linking C# code to Win32 program (gives LNK4248 error)