|
|
Comments and Discussions
|
|
 |

|
Thanks for Sharing. Very Good Article.
|
|
|
|

|
Hallo,
could anyone give some instruction for beginners of how to call a visual basic dll from visual c++ in Visual Studio 2010.
thanks...
|
|
|
|

|
Thanks for sharing this article.
I have a situation in which I am trying to access a third party DLL. I followed the instruction in this article, but at the end process, I get a compilation error C2027: use of undefined type 'type'. The IDL file of my DLL looks something like this:
library XAPI
{
interface IXField;
[
uuid(A6B99FCD-4D31-411A-A735-E7DC17AC1123),
helpstring("XField Object")
]
coclass XField {
[default] interface IXField;
};
[
odl,
uuid(19DE3CA1-CD87-4A89-B323-CE37EA23E1FB),
helpstring("Dispatch interface for IXField Object"),
dual,
oleautomation
]
interface IXField : IDispatch {
[id(0x000000c9), propget]
HRESULT Tag([out, retval] long* Value);
}
}
It has an interface IXField and a class XField.
The corresponding .h file created by midl:
typedef interface IXField IXField;
typedef class XField XField;
EXTERN_C const IID IID_IXField;
MIDL_INTERFACE("19DE3CA1-CD87-4A89-B323-CE37EA23E1FB")
IXField : public IDispatch
{
public:
virtual HRESULT STDMETHODCALLTYPE get_Tag(
long __RPC_FAR *Value) = 0;
};
EXTERN_C const CLSID CLSID_IXField;
class DECLSPEC_UUID("CB29D47C-A1FE-4803-A30C-68CA10058EC6")
XField;
My C++ code (TestXAPI.cpp) after including the header file:
HRESULT hr;
IXField * mXField = NULL;
hr = CoInitialize(0);
hr = CoCreateInstance(CLSID_IXField,NULL,CLSCTX_INPROC_SERVER,IID_IXFixField,(void**) &mXField);
long value = 0;
mXField->get_Tag(&value);
During compilation, the following error message occurred:
TestXAPI.cpp(101) : error C2027: use of undefined type 'IXField'
The error happens when I try to access the get_Tag() method.
I can see that the problem is because the class XField is declared without any implementation. My question is: wouldn't the actual code be implemented inside the DLL? And somehow I need to be able to link the DLL and the declaration?
I wonder if someone has a solution to this.
Thanks.
|
|
|
|

|
Thanks for the great articles it really helps someone new like me.
|
|
|
|

|
I have done the "Calling a VB ActiveX DLL from a MFC Client" exercise successfully.
I have a requirement that, adding a new Public function (eg fncDLL2())in VB DLL and make dll.
Now without building the vc++ application replace the dll in the current folder and run the exe. When i did the same i am getting "Creation Failed" error.
Please try to give the solution to my problem
|
|
|
|

|
I have created an activeX DLL. It contains a class as shown below
-----------------------------------------
Option Explicit
Public Type T
i As Integer
d As Double
l As Long
s As String
End Type
Public Function TypeValue() As Long
Dim a As T
a.i = 10
TypeValue = a.i
End Function
---------------------------------------------------
I can able to make dll but, when i try to compile .idl file using MIDL it's giving an error the error message is as follows
"midl\oleaut32.dll : warning MIDL2368 : error generating type library, ignored : Could not set UUID :
tagT"
|
|
|
|

|
Checked the PATH, INCLUDE, LIB env. Variables Tried on both Visual Studio Professional , Enterprise, Visual Studio.net2003 on a fresh installation after removing previous installations & deleting all LIB, INCLUDE, PATH , registry entries (using regedit), & did fresh installations. In command prompt, ran midl with & without executing VCVARS32.bat Copied the file vbTestCOM.idl in all LIB , INCLUDE, bin Dir checked with TestvbCOM.idl, vbTestCOM.idl still...NO EFFECT Still the Same ERROR :: MIDL1003 persists // OUTPUT same by both IDE & command prompt: Processing .\vbTestCOM.idl %CL% fatal error C1083: Cannot open source file: '%CL%': No such file or directory vbTestCOM.idl midl : command line error MIDL1003 : error returned by the C preprocessor (2) PLEASE HELP
|
|
|
|

|
I have a problem when i access the VB activeX DLL fuction which inturn call the regular DLL fuction from my VB application.I am using the late binding to access the ActiveX DLL from my VB application . Can you help me regarding this. You can suggest any other idea to resolve.
Thank you,
Regards,
KSMH
|
|
|
|

|
Anybody know to dynamically link the vb activex dll with vc?
Jothi Murugeswaran.S
|
|
|
|
|

|
is very old, but I liked it.
But I think with VS2005 and the .net technology there are easier ways. That could be interesting!
Greetings from Germany
|
|
|
|

|
Instead of using a pointer by using
_clsVBTestClass *IVBTestClass = NULL;
would it be better to use a CComPtr instead or a
CComQIPtr maybe?
E.g.
HRESULT hr;
CComPtr<_clsVBTestClass> IVBTestClass;
or
HRESULT hr;
CComQIPtr<_clsVBTestClass> IVBTestClass;
Just a thought
Tom
|
|
|
|

|
Hello,
Does any body know how to return a string-variable back to the C++ program; the article only shows it with a long-variable.
I followed the same steps with an extra VB-function that returns a string, but I can't get the VC++ program to work.
VC++ :
_bstr_t RetStrValue;
hr = IVBTestClass->DoString(bstrValue, &RetStrValue);
cout << "The returnstring is: " << RetStrValue << endl;
The C++ compiler says :
error C2664: 'DoString' : cannot convert parameter 2 from 'class _bstr_t *' to 'unsigned short ** '
VB-function :
Public Function DoString(ByVal strValue As String) As String
If strValue = vbNullString Then
DoString = ""
Else
DoString = "RETURN" & strValue * "RETURNNNN"
End If
End Function
|
|
|
|

|
hi
pls clear my doubt
the error are follow by the time of generating build Dll in vc++
this for using vb dll in vc++
fatal error C1010: unexpected end of file while looking for precompiled header directive
help me to know the result
Thanks
sridhar
|
|
|
|

|
i too got the same error.
Can anybody explain this????????????????
|
|
|
|

|
I got solved by selecting,....
Project->Settings->c/c++->category->Precomipled headers->Not using precompiled headers.
Thismay be useful for others.
Thanks,
|
|
|
|

|
For some reason if I include "stdafx.h" in my project, when I move the inclusion for "vbTestCOM.h" to *before* stdafx it is completely ignored, and if I include it *after* stdafx I get this error saying it doesn't even exist! What is going on here?
D:\backup\projects\Server\IOCP\srv\worker.cpp(11) : fatal error C1083: Cannot open include file: 'vbTestCOM.h': No such file or directory
|
|
|
|

|
hi,
I tried to do everything you explained above but when I tried to invoke the midl compiler E:\VCSource\TestVBCOM\TestVBCOM\midl vbTestCOM.idl /h vbTestCOM.h
it gave the following error
device is not ready..
do you know what might cause this?
thanks...
gül
|
|
|
|

|
Hello,
in this Article are a lot of errors:
:\Temp\TestVBCOM\TestVBCOM.cpp(9) : error C2065: '_clsVBTestClass' : undeclared identifier
C:\Temp\TestVBCOM\TestVBCOM.cpp(9) : error C2065: 'IVBTestClass' : undeclared identifier
C:\Temp\TestVBCOM\TestVBCOM.cpp(9) : warning C4552: '*' : operator has no effect; expected operator with side-effect
C:\Temp\TestVBCOM\TestVBCOM.cpp(18) : error C2065: 'CLSID_clsVBTestClass' : undeclared identifier
C:\Temp\TestVBCOM\TestVBCOM.cpp(21) : error C2065: 'IID__clsVBTestClass' : undeclared identifier
C:\Temp\TestVBCOM\TestVBCOM.cpp(32) : error C2227: left of '->CountStringLength' must point to class/struct/union
C:\Temp\TestVBCOM\TestVBCOM.cpp(35) : error C2001: newline in constant
C:\Temp\TestVBCOM\TestVBCOM.cpp(36) : error C2146: syntax error : missing ';' before identifier 'length'
C:\Temp\TestVBCOM\TestVBCOM.cpp(36) : error C2065: 'length' : undeclared identifier
C:\Temp\TestVBCOM\TestVBCOM.cpp(36) : error C2001: newline in constant
C:\Temp\TestVBCOM\TestVBCOM.cpp(36) : error C2059: syntax error : 'string'
C:\Temp\TestVBCOM\TestVBCOM.cpp(43) : error C2228: left of '.cout' must have class/struct/union type
C:\Temp\TestVBCOM\TestVBCOM.cpp(43) : error C2297: '<<' : illegal, right operand has type 'char [25]'
Error executing cl.exe.
TestVBCOM.exe - 12 error(s), 1 warning(s)
Sometimes you write "_clsVBTestClass", on other locations "_clsTestClass", or the projectname is sometimes "TestVBCom", sometimes "vbTestCOM". The Sourcecode in the article and in the zip are also not equal.
I can fix the errors for myself. But it is annoyed to fix so much errors in a so little project. --> Review this articel.
Peter
|
|
|
|

|
i followed all the steps but i couldnt compile .idl file..
when i type midl it says bad command or file name.
Do i have to install MIDL compiler ?
|
|
|
|

|
I get compiling copying the .idl file in VC/Bin folder so:
C:\Program Files\Microsoft Visual Studio\VC98\Bin
and then executing midl but i'm having problems also.
|
|
|
|

|
Yes, you need to reinstall Platform SDK. This might be caused by incomplete installation!
Janice Lee
|
|
|
|

|
MIDL compiler is normally installed with visual studio.
You must call vcvars32.bat (with full path) in your command window to set the correct environment before calling midl. File vcvars32.bat is optionally generated during installation of visual studio.
|
|
|
|

|
Checked the PATH, INCLUDE, LIB env. Variables Reinstalled Visual Studio 6.0 Tried on both Visual Studio Professional , Enterprise In command prompt, ran midl with & without executing VCVARS32.bat NO EFFECT Still the Same ERROR :: MIDL1003 persists // OUTPUT Window : Processing .\vbTestCOM.idl %CL% fatal error C1083: Cannot open source file: '%CL%': No such file or directory vbTestCOM.idl midl : command line error MIDL1003 : error returned by the C preprocessor (2) PLEASE HELP
|
|
|
|

|
eg:
#import "test.dll" no_namespace
I's a better way to do that.
|
|
|
|

|
My task is to call a VB activeX DLL function from a C++ DLL. After following the article by C. Lung on "Calling Visual Basic ActiveX DLLs from Visual C++", I am receiving the output "CoCreateInstance failed" with a return code of -2147467262.
Does anybody have any ideas why this would happen, or how to fix it? The VB DLL I am trying to call is registered on the server. The C++ wrapper DLL I created resides in the same folder as the VB DLL. I can provide more detailed info and code if necessary.
Thank you..
|
|
|
|

|
I get this same error.. Author please explain why this could happen!
|
|
|
|

|
I got the same error using VC6 SP5.
|
|
|
|

|
Try registering the dll to registry using regsvr32
|
|
|
|

|
Hi All
I am trying to return Recordset from my VB Dll Function
. I am using ADO 2.5 library while compliling vbCOMTest.idl
it is giving error in this statement
library vbTestCOM
{
// TLib : // TLib : Microsoft ActiveX Data Objects 2.5 Library : {00000205-0000-0010-8000-00AA006D2EA4}
importlib("msado25.tlb");
// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");
Error Description
D:\MFC\VBFromVC\TestVBCOM\vbCOMTEST.idl(12) : warning MIDL2015 : importlib not found : msado25.tlb
|
|
|
|

|
I have test this example and it works very good but I can't call an ActveX Control ( myctl.ocx written by Visual Basic) from Visual C++ ( Win32 Console App). Please help me do
Thanhyou very much !
(When I do similar with an ActiveX Control(myctl.oxc written by Visual Basic) an Error occur at runtime(run debug): Unhandled exception in TestVBCOM.exe(MSVBVM60.DLL): 0xC0000005: Access Violation )
|
|
|
|

|
Hi,
did you solve the problem of the exception? I have a similar problem with the second version of a Visual Basic ActiveX DLL received from a supplier. The first version of the DLL works ok.
Thanks
|
|
|
|

|
I have test this example and it works very good but I can't call an ActveX Control ( myctl.ocx written by Visual Basic) from Visual C++ ( Win32 Console App). Please help me do
Thanhyou very much !
(When I do similar with an ActiveX Control(myctl.oxc written by Visual Basic) an Error occur at runtime(run debug): Unhandled exception in TestVBCOM.exe(MSVBVM60.DLL): 0xC0000005: Access Violation )
|
|
|
|

|
I have been test this example and it works very good . But I can't calling an ActiveX Control ( myctrl.ocx) . please help me calling with an ActiveX Control
Thanhyou vey much !
|
|
|
|

|
Can somebody provide me with an example of how to pass arrays from a VB created ActiveX DLL to a VC++ app using the SAFEARRAY
|
|
|
|

|
#1, why does it seem that any project, other than console, is built with the knowledge of .idl files built in? Try it, just do a normal win32 app and add an idl file, it'll automatically compile without a custom build.
#2, when I tried compiling the idl from dos, I got an error about not finding oaidl.idl, even though it's in my path. But, when using the custom build settings, it worked fine, why?
|
|
|
|

|
I am running VC++, Version 5 and VB Version 5 under Windows NT, Version 4.
I want to call an ActiveX DLL written in VB 5 from a VC5 Client application. My ActiveX DLL returns a string. In order to understand how to do this I have written a simple test ActiveX DLL in VB 5:
Public Function LeftThree(strString As String) As String
LeftThree = Left(strString, 3)
End Function
The MIDL compiler produces a .h file in which the significant sections of code defining the interface to LeftThree seem to be:
virtual /* [id] */ HRESULT __stdcall LeftThree(
/* [out][in] */ BSTR strString,
/* [retval][out] */ BSTR __RPC_FAR *__MIDL_0015) = 0;
and
/* [id] */ HRESULT ( __stdcall __RPC_FAR *LeftThree )(
_clsTestCOM __RPC_FAR * This,
/* [out][in] */ BSTR __RPC_FAR *strString,
/* [retval][out] */ BSTR __RPC_FAR *__MIDL_0015);
What I would like to know is how to call LeftThree from the VC++ application. Could anybody help me on this? I would be very grateful for any advice and in particular for some sample code.
Regards,
David Hann
|
|
|
|

|
Hello,
Does any body know how to return a string-variable back to the C++ program; the article only shows it with a long-variable.
I followed the same steps with an extra VB-function that returns a string, but I can't get the VC++ program to work.
VC++ :
_bstr_t RetStrValue;
hr = IVBTestClass->DoString(bstrValue, &RetStrValue);
cout << "The returnstring is: " << RetStrValue << endl;
The C++ compiler says :
error C2664: 'DoString' : cannot convert parameter 2 from 'class _bstr_t *' to 'unsigned short ** '
VB-function :
Public Function DoString(ByVal strValue As String) As String
If strValue = vbNullString Then
DoString = ""
Else
DoString = "RETURN" & strValue * "RETURNNNN"
End If
End Function
|
|
|
|

|
HI, I have been trying to pass a picture from the picture box in VB to VC win32 dll , for some processing and then pass the same back to Picture Box.. Can any one help me out how should I declare a function in VC and the equivalent in VB thanx in advance Sreekant
|
|
|
|

|
You should transfer the picture in a approbiate format. For instance a HBITMAP, but it depends on your data.
I would do it another way which I think should be more easier, because there is no hazzle about the formatted data. I would write the pic to a file (*.bmp) and call the VC-dll with a path.
The first is a tougher task to do. SCNR
Greetings from Germany
|
|
|
|

|
How can i access the data sent as variant array from vb application in my vc++ atl com dll. I thank them now itself for the timly help rendered to me
|
|
|
|

|
Hi I have done everything in this tutorial, and all works great on my PC. When I move the code to another PC, however, I keep getting DLL not registered. Even in OLE Viewer. This is after I have run regsvr32 mydll.dll.
Please help.
|
|
|
|

|
http://216.26.168.92/vbsquare/activex/begobjects2/index3.html
this may help.
Al.
|
|
|
|

|
Hy,
My question is the opposite of your article!
How can I make a COM with VC++, what can call from VB.
Any special interface?
Special data types?
I made a simple COM, with only one function void (void) and the VB can't call it?
Zoltan
|
|
|
|

|
http://www.codeproject.com/useritems/simplecomserver.asp
Try to make the VC++ Component which suports automation
as go through this article and create autocomserver.dsp
project
|
|
|
|

|
Everybody says creation of dll in vc++ and accessing from VB.
Please tell me how to create dll in VC++ and Access from VC++ only.
I tried one sample program:
step-1: open new project and select win32 dyanamic link library type project.
step-2: i wrote a sample program in c++ file
#include
__declspec(dllexport) void print();
void print()
{
printf("Hello WORLD");
}
step-3: then i compiled ang got the .dll and .lib file successfully;
step-4: i kept the .dll file in system32 folder of windows
step-5: i create one more project using new project and select win32 console application.
step-6: in c++ file i wrote
#include
_declspec(dllimport) void __stdcall print();
void main()
{
print();
}
step 7: In project setting i gave the .lib file path name.
step 8: When i compiled this i got the error
What is this error
ompiling...
main.cpp
d:\dll\main\main.cpp(4) : warning C4518: '__declspec(dllimport ) ' : storage-class or type specifier(s) unexpected here; ignored
d:\dll\main\main.cpp(4) : warning C4230: anachronism used : modifiers/qualifiers interspersed, qualifier ignored
Linking...
main.obj : error LNK2001: unresolved external symbol "void __stdcall print(void)" (?print@@YGXXZ)
Debug/main.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
main.exe - 2 error(s), 2 warning(s)
|
|
|
|

|
hi friends,
how to call activex dll through c++ dll.
thanks in advance.
|
|
|
|

|
I Know i can use structures in COM object, for example i have the following one:
typedef struct _DataCar
{
float Passo[2];
float SetBack[2];
float Conv[4];
float Camber[4];
float StearingMax[2];
// ...
unsigned fCarStatus;
}
DataCar;
Is it correct to define a method as follow?
STDMETHOD(GetCarData)(/*[out]*/DataCar* pData);
Compilation got me a warning!
But now how can i retrieve the structure in VB?
i performed the following code in VB, but connection with my COM object fails:
Public Type DataCar 'I defined a structure to recieve the data
Passo(2) As Single
SetBack(2) As Single
Conv(4) As Single
Camber(4) As Single
StearingMax(2) As Single
fCarStatus As Single
End Type
Dim myCarData As DataCar
Set conn = New ISConnection 'Perfomes connection to my COM object
conn.GetCarData myDataCar 'trying to receive data
Thanx
|
|
|
|

|
What if your VB class returns another VB object and not a primitive?
|
|
|
|

|
The CoCreateInstance function keeps failing!!!
I made Class_Initialize and Class_Terminate functions which pop up message boxes. When I run the VC program, both of these functions are called because the two message boxes appear, which indicates that the VB DLL is being accessed, but they immediatly follow eachother, indicating that when the class given an instance, it is immediatly released. When I download the code example, the CoCreateInstance function still fails. Am I missing something???
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
| Type | Article |
| Licence | |
| First Posted | 18 Nov 1999 |
| Views | 429,721 |
| Bookmarked | 99 times |
|
|