I have created a COM callable DLL in C# .NET 2.0 and created a TLB
from the assembly using the .NET regasm tool.
In Borland C++ Builder 4.0 I go to Project->Import Type Library-> and
find my DLL's type library there and click "Ok" to import it.
BCB creates an HardwareCheck_TLB.cpp & HardwareCheck_TLB.h file.
In a cpp file of the project I want to use the DLL I put:
#include "HardwareCheck_TLB.h"
at the top.
Then in code if I try to declare an object of that type in code:
IHardwareCheck hc = new IHardwareCheck();
I get the following compiler error:
[C++ Error] Unit1.cpp(22): E2352 Cannot create instance of abstract
class 'IHardwareCheck'.
[C++ Error] Unit1.cpp(22): E2353 Class 'IHardwareCheck' is abstract
because of '__stdcall IHardwareCheck::IsExpress(wchar_t * *,TOLEBOOL
*) = 0'.
Anybody have any ideas how to get rid of this error?
Thanks!
COM clasess cannot be created using new. You need to use the CoCreateInstance system call (see MSDN) or some wrapper provided by Borland (such as the one mentioned by zer0_ring).
It should generate some TCoClassCreatorT<> types that you can do a
CoHardwareCheck::Create(&hc)
You may have to look at the tlibimp.exe that Borland distributes with its products. I've gone through this before with that program but never was able to get the Co classes generated, maybe you'll have better luck.
Related
I have written a program that creates chess diagrams using post script. I want to convert the resulting *.eps file to an equivalent *.jpg file using ghost script. I have succeeded in doing this in a C# project but I cannot get it to work in C++ or C++/CLI, either one. The problem is in getting access to the gsdll32.dll methods.
In C# I use this code:
[DllImport ("gsdll32.dll", EntryPoint = "gsapi_new_instance")]
private static extern int CreateAPIInstance (out IntPtr instance, IntPtr caller);
My attempts to use DllImport in C++ have failed.
In a C++/CLI project I get the following error when trying to add a reference:
Could not add a reference to 'S:\ScruffySoft\UseGhostScript\bin\Debug\gsdll32.dll' as it is not of a type or version current project can use.
In a C++ project I added the gsdll32.dll as a 'Solution item' and when building get the error message:
Error LNK1107 invalid or corrupt file: cannot read at 0x2B8 UseGhostScriptConsole S:\ScruffySoft\UseGhostScriptConsole\gsdll32.dll
So the question is: how do I get access to the ghost script DLL?
Thanks,
Dick
I'm trying to get an app working with a PLC. I'm using this library: https://github.com/FreeOpcUa/freeopcua
example code: https://github.com/FreeOpcUa/freeopcua/blob/master/src/examples/example_client.cpp
But when I include the header files(like in the example) from the library it gives an error:
Non-Virtual function 'DateTime::DateTime(const DateTime &)' declared pure.
When I search the specific line of this error it shows me this:
DateTime(const DateTime&) = default;
I already asked it on the github page, and they are saying it has something to do with my compiler. I never touched it, so it shouldn't be having odd options.
So how can I solve this? And if there is something wrong with my compiler, How can I change my compiler options to get it fixed?
Yes, bcc32 don't allow to create instance of abstract class. So you can change target platform to win64 and compile without errors.
Another way, as Thorsten Schöning said, you can use C++ Builder 10 with bcc32c based CLANG compiler and do it also without errors.
I built Qt from source (dlls) and am trying to build an application that uses the Qt dlls. I don't have a lot of experience with C++ so I'm running into what I'm sure is a very basic issue.
My builds are failing on the includes with errors like so:
Fatal error: QNetworkProxy: No such file or directory
Here is the g++ command I am using (I also used -L to add the correct folder to the lib path, but that also didn't work):
g++ -l..\..\wkqt\bin\QtCore4.dll -l..\..\wkqt\bin\QtNetwork4.dll -l..\..\wkqt\bin\QtWebKit4.dll -I..\include -Ishared -Ipdf -Ilib -Iimage -o ..\bin\wkhtmltopdf.exe pdf\*.cc lib\*.cc image\*.cc shared\*.cc
I tried in Visual Studio as well (assuming it wouldn't build, but I wanted to see if I could at least include the Qt dlls from there properly) and I am getting the same errors. Am I doing something wrong with the way I am compiling with g++? If I am linking with the Dlls properly then what is the proper way to use Qt functions from my code?
To clarify, I am not looking for how to properly use Qt. My question is: what is the proper way to use functions defined in any Dll from native C++ code? I apologize if this is a very basic question, but I'm unable to find a clear answer on Google and I don't have any experience with C++ and including third party libraries for use from C++ code.
DLLs can be used by dynamicly loading them and calling their used functions.
to call the exposed functions first define their syntax in the begining
suppose function is syntax is
BOOL MyFunction(int a,char* pszString)
then define syntax
#typedef BOOL (WINAPI *PMYFUNCTION)(int a,char* pszString)
then make object
PMYFUNCTION pfnMyFunction;
and get valid pointer by calling GetProcaddress after loadlibrarycall
HMODULE hlib= Loadlibrary("c:\\Mylib.dll");
if(hlib)
{ pfnMyFunction = (PMYFUNCTION)Getprocaddress(hlib,"MyFunction"); }
Hope this helps...
I am trying to implement the automatic updater for my application written in C++/Qt. It should work on Mac OS X. I've searched over the web and found out that Sparkle framework should be suitable for my needs. I added Sparkle framework 1.5 b6 to my xcode project, also added the header file:
#include <Sparkle/Sparkle.h>
Now, when I try to build the project, the compiler gives me a lot of errors in SUVersionComparisonProtocol.h and SUUpdater.h:
Expected unqualified-id: #protocol SUVersionComparison
Expected unqualified-id: #end
Expected unqualified-id: #interface SUUpdater: NSObject {
etc etc
I see those headers are written in Objective-C, so it seems like C++ compiler simply can't handle them. However, I know C++ applications that use Sparkle. So could somebody tell me how should it be used in C++ applications?
Indeed, you need to mix C++ and Objective-C.
Here is an excellent explanation, along with an implementation example: http://el-tramo.be/blog/mixing-cocoa-and-qt/
and here is a C++/Qt project that builds a Qt-usable dylib wrapper for Sparkle: https://github.com/Roxee/qt-roxeemegaup/
I am converting my project to use DLLs and am trying to break apart my Singleton class to avoid using templates.
My class, LudoMemory, originally inherited from Singleton. I am trying to give it the functions to destroy and create itself now and have my main engine not rely on the Singleton.
I have written a simple destroy method like such:
LudoMemory *memory_Singleton = NULL;
void LudoMemory::Destroy()
{
LUDO_SAFE_DELETE(m_Singleton)
}
and upon running the program (no compiler errors) I recieve this error:
The procedure entry point
?Destroy#LudoMemory##SAXXZ could not
be located in the dynamic link library
LudoCore.dll
LudoCore is the project that LudoMemory belongs to. Why is this happening? How can I solve it?
you don't have multiple versions of ludocore.dll on your system, do you?
Procedure entry points errors usually mean: you compiled your project against ludocore.lib version x, and when running the program, it uses ludocore.dll version y, and version y does not define LudoMemory::Destroy().
Jacob's answer about multiple DLL versions seems likely.
Also, with some build systems, you must explicitly list which functions will be exported in a DLL.
Research your build environment, and see if you must provide a list of methods to be exported as an entry-point.
In Visual Studio build environment, also you could try by disabling the References in Linker Optimization Settings [ No(/OPT:NOREF)]