|
int hello = (char)'a';
In C++ you can do mathematical operations on chars, you can say
char b = 123 or
char b = 'a' .
|
|
|
|
|
Cool, thanks!
Frank
|
|
|
|
|
Just curious...what kind of projects have a "common" folder? if you want to include some static libraries with your project, how do you include them? I amlooking at my project and I don't see a "common" folder, yet that's where it appears that I should be putting my stuff...
any ideas?
|
|
|
|
|
i put each static lib in its own folder. that way, i can get to it from any workspace/project that needs to.
-c
Cheap oil. It's worth it!
|
|
|
|
|
What does it mean when you try to link to a static library and you get this error:
LINK : warning LNK4098: defaultlib "MSVCRTD" conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/test.ocx : fatal error LNK1169: one or more multiply defined symbols found
|
|
|
|
|
It means that you are linking your code with MSVCRTD and some other version of the c++ libraries that define the same functions. To get around this Open the link tab of the project settings for your executable and select the input category and then put MSVCRTD in the Ignore libraries edit box.
John
|
|
|
|
|
Hi,
I'm making a dll which needs to export classes, but as this is going to be used to make compiler independant extensions, I would like to keep the code as platform independant possible, so does anyone know a way of doing this:
class __declspec(dllexport) CFoo which would work on any compiler. __declspec(dllexport) according to the MS documentation seems to be microsoft specific. If possible I would like to keep away from writing into the .DEF file, but if I have to does anyone know how to do it right?
Thanks for your time...
England 1 : Sweden 1
We don't stand a chance against Argentina!
Joel Holdsworth
|
|
|
|
|
#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.
|
|
|
|