|
#ifdef _MSC_VER
#if EXPORTING
#define DLLAPI __declspec(dllexport)
#else
#define DLLAPI __declspec(dllimport)
#endif
#else
#error "define a declspec for this compiler
#endif
class DLLAPI CFoo
This would be enough for you.
That being said. I think DEF file is much better way to export then using __declspec(dllexport). You should however use __declspec(dllimport) so that the linker optimizes the stub linkage.
|
|
|
|
|
Rama Krishna wrote:
I think DEF file is much better way to export then using __declspec(dllexport).
How do you export an entire class then with a .DEF file?
Best regards,
Alexandru Savescu
|
|
|
|
|
Get all the decorated names of the public methods of the class and put them in the .DEF file. MFC does the same way.
|
|
|
|
|
Hi!
I have written an NT Service to monitor an application execution.
The NT Service detect properly when the application crashes (deadlock).
In order to reboot the system I am using the API function ExitWindowsEx to reboot the system, but it doesn’t work very well. As a matter of fact, when I call this API function the system shows a blue screen and stay in this situation timelessly.
The code that I am using (the shut down example from MSDN) is show below (I guess I have got the right privilege).
Does anybody know how can I make the system reboot properly?
Thank you very much for your attention.
Sergio
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
error("OpenProcessToken");
// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
error("AdjustTokenPrivileges");
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
error("ExitWindowsEx");
|
|
|
|
|
BTW, Welcome Sergio! I saw your name as a new member!
For your problem, I think you didn't get the right privilege, try
adding a Messagebox or something in your app to verify that.
I am pretty sure you didn't obtain the privilege.
Good luck!
One good thing about getting older, you don't lose the ages you've been!
|
|
|
|
|
Hi Sergio ! Welcome to CP !
I don´t know if this would help but try to change the ExitWindowsEx stuff for this:
InitiateSystemShutdown(NULL, NULL, 0, TRUE, FALSE);
Mauricio Ritter - Brazil
Sonorking now: 100.13560 Trank
The alcohol is one of the greatest enemys of man, but a man who flee from his enemys is a coward.
|
|
|
|
|
G'Day Sergio,
A while ago I wrote a NT Service that would reboot my pc. As suggested by Mauricio I used InitiateSystemShutdown. If you want the pc to reboot rather than shutdown then the last parameter should be TRUE rather than FALSE in Mauricio's example.
With respect to priveleges - SE_SHUTDOWN_NAME is the only one that I have used.
Good Luck
Richard.
|
|
|
|
|
If you are a VC++ Guru and knowz how to create XML based IE Toolbars, then leave a comment here with your email and sample work url's
We have lot of orders of IE Toolbars. Also, let us know how much do you charge per toolbar.
Thanks..!!
|
|
|
|
|
http://www.codeproject.com/atl/rbdeskband.asp
This article is a wazard for creating deskbands.
http://www.codeproject.com/tools/codeprojectsearchbar.asp
The codeproject IE bar is a nice example of how it all works.
I don't know about how XML will work into that, but this is what CP has to offer!
With time we live, with money we spend!
Joel Holdsworth
|
|
|
|
|
Hi
I'm new to c++ and need a little help loading dll's at run-time. I found a bit of code on msdn, edited it and crossed my fingers but it didn't work . Can anyone see why?
-------------------------------------------------
int CMainFrame::LoadPlugins()
{
typedef UINT (CALLBACK* LPFNDLLFUNC)();
HINSTANCE hDLL[5]; // Handle to DLL
LPFNDLLFUNC lpfnDllFunc[5]; // Function pointer
UINT uReturnVal = 0;
CString PluginName[5] = {"plugin1.dll", "plugin2.dll"};
for (int i = 0; i != 5; ++i)
{
// Use Plugin name to load plugin
hDLL[i] = LoadLibrary("Plugins\\" + PluginName[i]);
if ((hDLL[i]) != NULL)
{
AfxMessageBox("Loaded Plugin : " + PluginName[i]);
lpfnDllFunc[i] = (LPFNDLLFUNC)GetProcAddress(hDLL[i], "Load");
if (!lpfnDllFunc[i])
{
// handle the error
AfxFreeLibrary(hDLL[i]);
AfxMessageBox("Couldn't Execute Plugin : " + PluginName[i] + ". No such function.");
}
else
{
// call the function
uReturnVal = lpfnDllFunc[i]();
AfxMessageBox("Function Called");
}
}
else
{
if (PluginName[i] != "")
AfxMessageBox("Couldn't Load Plugin : " + PluginName[i]);
}
}
//if a return value was set at least 1 plugin loaded
if (uReturnVal)
return 1;
}
-------------------------------------------------
It will load the dll but not execute the function.
Any help would be appreciated
Thanks
|
|
|
|
|
Anonymous wrote:
lpfnDllFunc[i]();
How about (*lpfnDllFunc[i])();
|
|
|
|
|
Thanks for the reply, i think the problem might be in the dll, i'm not sure i'm exporting the function correctly.
The line: lpfnDllFunc[i] = (LPFNDLLFUNC)GetProcAddress((hDLL[i]), "Load");
returns NULL, does this mean it cant find the function?
I'm using the folowing code to export it
------------------------------------------
__declspec( dllexport ) int CPluginApp::Load()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
AfxMessageBox("Inside DLL");
return 1;
}
------------------------------------------
Thanks again for the help, as i said i'm a newbe and i've taken on a rather large project for my first proper C++ app, got quite a complex UI sorted but this DLL stuff is giving me a headache.
Do you know of any system DLL's that export functions i might try and access to see if the code in my exe works? (at least then i could concentrate on exporting from the DLL correctly)
|
|
|
|
|
Anonymous wrote:
The line: lpfnDllFunc[i] = (LPFNDLLFUNC)GetProcAddress((hDLL[i]), "Load");
returns NULL, does this mean it cant find the function?
When something is so clearly documented and you display you haven't even bothered to look it up in the documentation before wasting our time and bandwidth, do you really expect to get any more answers?
|
|
|
|
|
I have looked it up in the documentation, that's how i've got this far, i'm attempting to teach myself c++ and occasionally run into problems, there's no need to be such an arse about it. If you don't want to help dont reply.
|
|
|
|
|
I wasn't being an arse just for the sake of it, it was to make you realize that to deserve help you should at least have exhausted your own sources of information before asking for help. Since knowing about pointers, and especially NULL pointers, is among the most basic aspects of this language I (apprently falsely) assumed you knew it.
May I suggest (and this is not trying to be a prick, this is the helpful me that is writing) that you have a look around the 'net? Googling for e.g. "beginners c++" can probably turn up quite a lot.
Reading comp.lang.c++.moderated, even the archives at http://groups.google.com, can probably turn up a lot of information.
I don't know what edition of MSVC you are using, but there are loads of samples in e.g. the SDK folder. MSDN also have many samples.
|
|
|
|
|
Hello,
I need paint dotted line using Win32API with GDI. I'm trying to draw focusRect, but with exact color, not inverting the background like DrawFocuRect does.
If I use pen style PS_DOT the pen is not exactly dotted - there are small lines.
I need one pixel colored and one transparent.
Have you any idea how to draw it?
I've looked at DrawFocusRect code and it calls undocumented PolyPatBlt
Ondra
|
|
|
|
|
Did you try to use an userpen? This is a way how to make a doted line too.
LOGBRUSH LogBrush;
LogBrush.lbColor = RGB(255,0,0);
LogBrush.lbStyle = BS_SOLID;
DWORD Spaces[] = {1,1};
CPen MyPen2(PS_USERSTYLE|PS_ENDCAP_FLAT|PS_GEOMETRIC,0,&LogBrush,2,Spaces);
|
|
|
|
|
I need the functionality of CFileFind for a project, but I can't be dependent on MFC for this project. Is there an API equivalent, or better a portable library for doing this? I know Boost has a class dir_it that will do it, but it looks like its still in beta.
|
|
|
|
|
CFileFind is based on a Win32 API. To do it w/out MFC, use something like this:
WIN32_FIND_DATA FindFileData;
HANDLE hFind = FindFirstFile(strCurrentPath + m_szREPORT_FILTER, &FindFileData);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
} while ( FindNextFile( hFind, &FindFileData) );
FindClose(hFind);
}
--------
Life is fraught with opportunities to keep your mouth shut. --Shog9 --
|
|
|
|
|
You could also use _findfirst() , _findnext() and _findclose() .
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
CFileFind is supported by ATL so a pure Win32 API project should support CFileFind.
- Michael Haephrati מיכאל האפרתי
|
|
|
|
|
Is there an equivalent of CString FormatMessage for STL strings and wstrings?
thanks
|
|
|
|
|
nope.
-c
Cheap oil. It's worth it!
|
|
|
|
|
None that I am aware of. However you can use sprintf.
Best regards,
Alexandru Savescu
|
|
|
|
|
I am trying to create a fstream member function. However, no luck !
I am using VC bw..
this is what I have
yyyy.h
#include <fstream>
class x
{
public:
protected:
ofstream of;
};
that's all.... and I get the following error:
error C2872: 'ofstream' : ambiguous symbol
However, when I move the same declaration to the cpp file, everything works?
So, how do I go about creating a member variable for a file pointer?
thanks
|
|
|
|