|
SC_HANDLE hScm = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS);
SC_HANDLE hService = OpenService(hScm, sServiceName, SERVICE_ALL_ACCESS);
StartService(hService, 0, NULL))
|
|
|
|
|
thanks a lot
should I include a special library ?
There is always something to learn
|
|
|
|
|
|
yes, StartService
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I was busy creating a Dll for some basic game engine (just for myself)
For the input, I would like to have some general function pointers inside my dll which I want to be able to reference to other functions from code based upon my exe file.
just like this:
<br />
on_a = function_to_do_on_A;<br />
on_esc = function_to_do_on_Esc;<br />
where on_a comes from the dll and the function_to_do_on_A comes from the application.
this is my code:
<br />
Dll:<br />
.h<br />
#define ENGINE_EXPORTS<br />
#ifdef ENGINE_EXPORTS<br />
#define ENGINE_API __declspec(dllexport)<br />
#else<br />
#define ENGINE_API __declspec(dllimport)<br />
#endif<br />
<br />
.cpp<br />
namespace Engine<br />
{<br />
namespace Input<br />
{<br />
ENGINE_API void (*on_a)(void);<br />
ENGINE_API void (*on_b)(void);<br />
ENGINE_API void (*on_c)(void);<br />
}<br />
}<br />
<br />
<br />
Exe:<br />
.cpp<br />
void FuncA(void)<br />
{<br />
MessageBox(NULL, L"FuncA called!", L"NOTIFICATION!", MB_OK);<br />
return;<br />
}<br />
<br />
int main()<br />
{<br />
Engine::Input::on_a = &FuncA;<br />
return 0;<br />
}<br />
<br />
errors<br />
on_a is not a member of Engine::Input<br />
on_a undeclared identifier<br />
<br />
<br />
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<br />
Exe:<br />
.cpp<br />
int main()<br />
{<br />
{<br />
using namespace Engine::Input;<br />
on_a = &FuncA;<br />
}<br />
return 0;<br />
}<br />
<br />
errors<br />
on_a undeclared identifier<br />
<br />
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<br />
<br />
.h<br />
namespace Engine<br />
{<br />
namespace Input<br />
{<br />
extern ENGINE_API void(*on_a)(void);<br />
}<br />
}<br />
<br />
error LNK2001: unresolved external symbol "void (__cdecl* Engine::Input::on_a)(void)" (?on_a@Input@Engine@@3P6AXXZA)<br />
What am I doing wrong? Why is my function pointer not being exported? And how to fix this problem?
Many thanks in advance.
ps. I am using VS2008
modified on Sunday, April 27, 2008 4:19 PM
|
|
|
|
|
Are you linking the exe to the import library (.lib) created by the DLL build?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
yes as follows..
<br />
#include "..\Engine\Engine.h"<br />
#if defined(DEBUG) | defined(_DEBUG)<br />
#define USE_DEBUG_ENGINE<br />
#endif<br />
<br />
#ifdef USE_DEBUG_ENGINE<br />
#pragma comment(lib, "..\\Debug\\Engine.lib")<br />
#else<br />
#pragma comment(lib, "..\\Release\\Engine.lib")<br />
#endif<br />
normal functions (and classes) declared within the namespace are working properly
for instance:
<br />
int Height = Engine::GetHeight();<br />
returns the proper value
|
|
|
|
|
The first version of your EXE code works for me as long as
that last header file code is included in the EXE cpp file.
Exe:
.cpp
namespace Engine
{
namespace Input
{
__declspec(dllimport) void (*on_a)(void);
}
}
void FuncA(void)
{
MessageBox(NULL, L"FuncA called!", L"NOTIFICATION!", MB_OK);
return;
}
int main()
{
Engine::Input::on_a = &FuncA;
return 0;
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The namespace Engine and it's 'member'- namespace Input are within the Dll file..
This means that the declaration is within the Dll file:
ENGINE_API void (*on_a)(void);
if I put the following code above the main function of mine:
namespace Engine
{
namespace Input
{
__declspec(dllimport) void (*on_a)(void);
}}
I get the following warning:
warning C4273: 'Engine::Input::on_a' : inconsistent dll linkage
followed up with an error:
error C3861: 'on_a': identifier not found
|
|
|
|
|
DllFile.h :
#ifdef ENGINE_EXPORTS
#define ENGINE_API __declspec(dllexport)
#else
#define ENGINE_API __declspec(dllimport)
#endif
namespace Engine
{
namespace Input
{
ENGINE_API void (*on_a)(void);
ENGINE_API void (*on_b)(void);
ENGINE_API void (*on_c)(void);
}
}
DllFile.cpp :
#define ENGINE_EXPORTS
#include "DllFile.h"
ExeFile.cpp :
#include "DllFile.h"
int main()
{
Engine::Input::on_a = &FuncA;
return 0;
}
|
|
|
|
|
thanks, that already helped a lot..
(the DllCpp was the problem, #define over there instead above the header..)
Since multiple header files all include this one (Engine.h),
I get several (7) Errors
Error LNK2005: "void (__cdecl* Engine::Input::on_a)(void)" (?on_a@Input@Engine@@3P6AXXZA) already defined in Engine.obj LuaScriptor.obj
But I think I can get around that problem, or just by simply putting everything inside a single header and source file.
Thanks to all for the support and the quick help
EDIT:
Fixed all (Copy everything to Engine.cpp and Engine.h), thanks
modified on Sunday, April 27, 2008 6:10 PM
|
|
|
|
|
Please,advise me that how do I get time of system in C++ language .Thanks
|
|
|
|
|
|
|
dear sir ,
i am using visual studio 2008 , and i am running the program ( that help me use the matlab in c++) but every time i try to run it appear to me this
Unhandled exception at 0x0001aa3a in teste.exe: 0xC0000005: Access violation reading location 0x0001aa3a.
and the file gs_support.c open and point on the part
#if defined (_WIN64)
cookie = systime.ft_scalar;
#else /* defined (_WIN64) */
cookie = systime.ft_struct.dwLowDateTime;
cookie ^= systime.ft_struct.dwHighDateTime;
#endif /* defined (_WIN64) */
can anyone help me , i download the program that read the function for the matlab from the codeproject from this link
link [^]
|
|
|
|
|
Greetings Programmers:
I would greatly appreciate your advice.
A few years ago, I wrote a program to automate a radio station. The program has worked well, but all the values are "hard-coded" -
every time the station changed their schedule, I had to re-code, re-compile and re-test. I am trying to develop an engine that will
read the values from a text file, giving the station personnel the ability to program the station themselves.
I am using CStdioFile to read the file. 99 times out of 100, it works perfectly - but randomly throws an exception. (The file exists,
and I don't know why it throws an exception; perhaps lack of a handle?) This is the code I use to read the file:
<CStdioFile File;
try
{
CStdioFile File(AutomationFile,CStdioFile::modeRead);
File.Seek(FilePosition,0);
int NumberOfCharactors=File.ReadString(StringRead); //StringRead is a CString
File.Close();
}
catch (CException *e)
{
TryAgain();
e->Delete();
}>
In TryAgain() I start the process over again to read the file. There is no use in creating an error message, as no one is at the station to see
it or do anything about it.
My questions:
1) Would you use another way to open and read the file?
2) How would you deal with the rare exception?
Thanks in advance for any opinions.
Gary
|
|
|
|
|
Member 3301229 wrote: I am using CStdioFile to read the file. 99 times out of 100, it works perfectly - but randomly throws an exception. (The file exists,
and I don't know why it throws an exception; perhaps lack of a handle?)
From CException::ReportError() you can know why its failed. [if you can reproduce by running it 100 times ]
Member 3301229 wrote: 1) Would you use another way to open and read the file?
You can also use C++ file streams.
Member 3301229 wrote: 2) How would you deal with the rare exception?
If the exception is so rare, it would be difficult to find and fix it. Being in maintenance project for more that one and half years, the strategy i used to use is to add extra traces and logs. So that you can catch the exception next time.
Regards,
Jijo.
________________________________
http://weseetips.com - Visual C++ technical tips.
|
|
|
|
|
Member 3301229 wrote: and I don't know why it throws an exception; perhaps lack of a handle?)
Why are you not using CFileException[^] to determine why the failure occurs. You should modify the catch block as: catch(CFileException* e)
Member 3301229 wrote: 1) Would you use another way to open and read the file?
Not really. If it failed the first time it will probably fail the second time.
Member 3301229 wrote: 2) How would you deal with the rare exception?
I would throw or log an error so I could determine the cause for failuire.[^].
One more thing... Make sure that you limit the code in your try/catch block so that it only contains code pertaining to CStdioFile operations.
Best Wishes.
-David Delaune
|
|
|
|
|
any compiler allow this?
wchar_t *p="abc";
Just mean that when compiling in unicode mode, ansi is not considered any more.
|
|
|
|
|
followait wrote: any compiler allow this?
wchar_t *p="abc";
I think any compiler allowing the above will be out of the C++ standard.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
followait wrote: Just mean that when compiling in unicode mode, ansi is not considered any more.
What do you mean by that? Is that a question?
ANSI is considered any place you use ANSI characters in a string.
There's no "Unicode mode"...the unicode preprocessor definitions are
used to conditionally compile certain APIs and structures a certain way, but
you can freely use character arrays of any type you want, anywhere you want.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
When developing a unicode application, all string should be unicode by default, so does ANSI.
I think it makes code more clear with no drawback, doesn't it?
|
|
|
|
|
Not yet, as far as I know.
Maybe a compiler switch like "treat string literals as unicode" for default string type, similar to /J option. MS compiler team may consider your request within forthcoming release.
|
|
|
|
|
e.g i have 4 states 0 0 0 0
with 2(two one's as input) as input i.e 4C2 = 6
i want to print all states
need a unique algorithm for any number
|
|
|
|
|