|
Hi,
Are you trying to use a class from that DLL?
Becaue in order to do so , you can't just create an instance of that class from your application,
because the constructor of that class is not being exported.
In order to use class from the DLL,your DLL should export a function which create that instance
and return a pointer to the created object.
For example,if you are trying to use a class called MyDllClass,then you need to export the following method:
MyDllClass *CreateMyDllClass()
{
return new MyDllClass;
}
Goodluck,
Eli
|
|
|
|
|
Eli, thanks for your (fast) reply!!
But I still got the same linking-error message.
Ok, this is what the cpp-file in vc++ looks like:
#include "stdafx.h"
#include "SHA.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
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 variable
SHA_API int nSHA=0;
// This is an example of an exported function.
SHA_API int fnSHA(void)
{
return 42;
}
// This is the constructor of a class that has been exported.
// see SHA.h for the class definition
CSHA::CSHA()
{
return;
}
CSHA *CSHA::New()
{
return new CSHA();
}
//--------------------------------------------------
This is the h-file (which I also use in my borland project):
#ifdef SHA_EXPORTS
#define SHA_API __declspec(dllexport)
#else
#define SHA_API __declspec(dllimport)
#endif
// This class is exported from the SHA.dll
class SHA_API CSHA {
public:
CSHA(void);
CSHA* New(void);
// TODO: add your methods here.
};
extern SHA_API int nSHA;
SHA_API int fnSHA(void);
//--------------------------------------------------
Borland cpp-file:
#include <vcl.h>
#pragma hdrstop
#include "sha.h"
CSHA* dll();
#pragma argsused
int main(int argc, char* argv[])
{
CSHA test;
CSHA* h = test.New();
return 0;
}
|
|
|
|
|
First,In the header of the DLL,put all exported functions and veriables inside the following block:
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
For example:
#ifdef __cplusplus
extern "C" {
#endif
class SHA_API CSHA {
public:
CSHA(void);
CSHA* New(void);
};
extern SHA_API int nSHA;
SHA_API int fnSHA(void);
#ifdef __cplusplus
}
#endif
In addition,your DLL solution should contain also a "*.def" file.
in that file you should add all the exported functions according to the following
example :
EXPORTS
fnSHA @1
Another exported function @2
Now,build your DLL again,and make sure that your application links to the correct dll/lib file.
Eli
|
|
|
|
|
I used the code you sent me, but I get compile error (C2470) You don't happen to have a working example of a cpp-file, h-file and def-file I could check?
And once again, thanks alot for you help!
/Martin
|
|
|
|
|
Hi Martin,
smsmfe wrote: I used the code you sent me, but I get compile error (C2470)
From MSDN :
Visual C++ Concepts: Building a C/C++ Program
Compiler Error C2470
'function' : looks like a function definition, but there is no formal parameter list; skipping apparent body
A function definition is missing its argument list. The following sample generates C2470:
int MyFunc {
};
int main(){
MyFunc();
}
This error may also be issued on a brace-enclosed initialization that is missing an =.
int arr[] { 1, 2, 3, 4, 5 };
Instead, you should use:
int arr[] = { 1, 2, 3, 4, 5 };
Can you post your source code after using my code?
Maybe I can see something you missed?
Regards,
Eli
|
|
|
|
|
h-file:
#ifdef __cplusplus
extern "C" {
#endif
// This class is exported from the SHA.dll
class SHA_API CSHA {
public:
CSHA(void);
CSHA* New(void);
// TODO: add your methods here.
};
extern SHA_API int nSHA;
SHA_API int fnSHA(void);
#ifdef __cplusplus
}
#endif
cpp-file:
// SHA.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "SHA.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
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 variable
SHA_API int nSHA=0;
// This is an example of an exported function.
SHA_API int fnSHA(void)
{
return 42;
}
CSHA::CSHA()
{
return;
}
SHA_API CSHA* New()
{
return new CSHA();
}
|
|
|
|
|
I also can't call the function fnSHA()
Same err: [linker error] unresolved external 'fnSHA()' referenced from...
|
|
|
|
|
Hello Friends.
I need to compare two string in which one is of type WCHAR * and other is of type char * .
if anybody know how to do it. please tell me.
|
|
|
|
|
I think its better to convert char* to wchar* and then compare...
- NS -
|
|
|
|
|
Convert your char* to wchar* using MultiByteToWideChar
and then use wcscmp to compare these two strings...
|
|
|
|
|
Hello people,
I wish to save an excel sheet programmatically
I tried using the following:
_Application app;<br />
.<br />
.<br />
COleVariant strFile(_T("C:\\Temp\\Disc.xls"));<br />
app.SaveWorkspace(strFile);
BUt this does not save it by itself, it instead opens a 'Save As' box when i had expected it save it automatically as Disc.xls at location C:\Temp\
Is there something wrong in waht i m doing?? Or how do i achieve it...
|
|
|
|
|
There are normally 3 objects of interest when automating excel the Application, the Workbook, and the Worksheet. Instead of trying to save the Workspace why not save the Worksheet or Workbook. Both of those objects have a SaveAs method.
|
|
|
|
|
i tried using workbook.SaveAs()....but i am not getting the hang of parameters i need to pass...i tried searching on the net too.....didnt find anything...can you help??
All i want to do is save in a specified path as a specified type..
Can you provide me an example??
|
|
|
|
|
Try this
<br />
COleVariant varFile(_T("C:\\Temp\\Disc.xls"));<br />
COleVariant varFileFormat((long)0xFFFFEFD1);<br />
COleVariant varTRUE((short)-1,VT_BOOL);<br />
COleVariant varFALSE((short)0,VT_BOOL);<br />
COleVariant varOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR);<br />
workbook.SaveAs(varFile, varFileFormat, varOptional, varOptional, varTRUE, varFALSE, 1, varOptional, varTRUE, varOptional, varOptional);<br />
|
|
|
|
|
Thanks a lot it worked[ ]
|
|
|
|
|
I am using a two dimensional array to read the image data.If i increase the indexes to large value >500 i am getting Unhandled exception:stack overflow.How to overcome this problem.
Regards
|
|
|
|
|
Some code and more detailed informations would be welcome.
|
|
|
|
|
Firstly, show some details or you have little hope of getting help. I would guess you're storing the array on the stack; if it's a really big array the heap is the correct choice. Let’s do some calculations. Assume a 2D array of int s with each dimension set to 500. The space required is: sizeof(int) *500*500 = 4*500*500 = 1,000,000. That’s nearly a megabyte on the stack! The default stack size used by the linker is 1 MB. If I’m correct nearly all your stack is being used by one variable!
Steve
|
|
|
|
|
Hi all. I've been trying to use openmp directives to boost preformance. I've managed to make it work, by using stuff like #pragma omp parallel for . But it doesn't work correctly: instead of improving performance, i get better results without it. I've tried different scenarios without results. Has anyone encountered such problems, or used OpenMP successfully so I may get some tips ?
there are no facts, only interpretations
|
|
|
|
|
Maybe your parallelization strategy for this specific loop is causing cache misses. Try redesigning the loop and see if you can improve cache hits. Its very important to test several variations of the critical loop. Also test both shared and privatization clauses on some variables, you may get better performance through selective privatization. Keep in mind not all nested loops benefit from parallelization.
Best Wishes,
-David Delaune
|
|
|
|
|
on windows platform,how to program judge Trojan wooden horse with c++.
many trojan wooden horse programs exist as dll file, how can they run?
how do trojan wooden horse infall pc.
|
|
|
|
|
NiHao, Is google translator not working again?
A dll on it's own is harmless, but when a program loads it, the bad code inside will run. A virus scanner looks at the bytes inside any memory looking for a specific sequence 's of bytes.
|
|
|
|
|
In SDI project I need to call some function that create in CView at CDocument class.
but when I declare as CMyView m_view in header file of *Doc.h I got a lot of error.
Please give me some idea for solve this problem.
|
|
|
|
|
use a forward declaration for the view...
// In the CYourDocument header file toward the top
class CYourView;
|
|
|
|
|
Also, here's a method you can create in your document class that will simplify getting the view pointer.
// Document declaration file (.h)
public:
CYourView* GetView();
// Document implementation file (.cpp)
CYourView* CYourDoc::GetView()
{
// Assumes this is an SDI app
POSITION position=GetFirstViewPosition();
if (position) {
return (CYourView*)GetNextView(position); // Get the only view
}
return NULL;
}
|
|
|
|