|
Hi,
Create NT Service using ATL COM appwizard.
In StdAfx.h file, include <afx.h> as shown below
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <afx.h>
//#define STRICT
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
Now u can use MFC in Service .
Cheers,
Anand
The chosen One
|
|
|
|
|
There is an easy way aswell , User CreateService API , it's takes an Excutable Name and register that as a service .
Atif
|
|
|
|
|
Hello, everyone!
I want to write a console application using VC++ 6.0 to invoke IE to load a html file which
resides on the same path of my application.
My trouble is, I do not know how to locate the executable file of IE, I want to write a
machine independent application and it is impossible to hard code the path of IE in my
program. Maybe I should read from registry or environment variable?
Who can help? Can you give me a sample?
Thanks in advance,
Geo
|
|
|
|
|
CreateProcess will look up the path to the executable, although this isn't that advisable (because an attacker could substitute a different IEXPLORE.EXE earlier in the path).
You might be better off using ShellExecuteEx directly on your HTML file, which will load the program registered to open HTML files.
|
|
|
|
|
Thanks, Mike buddy!
I have make a reference of MSDN of ShellExecuteEx. I have never used this function before, and I find the SHELLEXECUTEINFO Structure is too complicated. So, can you tell me how to fill the value of each fields of this structure in my simple example?
regards,
Geo
|
|
|
|
|
I'd suggest something like:
SHELLEXECUTEINFO sei = { 0 };
sei.cbSize = sizeof( sei );
<font color="green">
sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_FLAG_DDEWAIT;
sei.lpVerb = _T( "open" ); <font color="green">
sei.lpFile = _T( "myfile.htm" );
sei.nShow = SW_SHOWNORMAL; I've used the SEE_MASK_FLAG_NO_UI flag to prevent any message boxes coming up if there's an error. I've also added SEE_MASK_FLAG_DDEWAIT to ensure that launching the file using DDE works - Internet Explorer uses DDE to reuse an existing window if the user has IE configured that way.
You could leave the lpVerb variable set to NULL in order to use the user's default verb (the one in bold when right-clicking an HTML file) but the user could potentially have set this to do something different, rather than Open.
|
|
|
|
|
Thanks, Mike buddy!
I have tried your method in my VC++ 6.0 console application, but there are 5 errors. Here are the source codes:
Source Code:
----------
#include <shellapi.h>
#include <windows.h>
int main (int argc, char** argv)
{
SHELLEXECUTEINFO sei = { 0 };
sei.cbSize = sizeof( sei );
// Add the SEE_MASK_NOCLOSEPROCESS flag
// if you want to wait until the browser is closed
sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_FLAG_DDEWAIT;
sei.lpVerb = _T( "open" ); // Could leave NULL
sei.lpFile = _T( "myfile.htm" );
sei.nShow = SW_SHOWNORMAL;
//ShellExecute(0, "open", "iexplore.exe", "http://www.codeguru.com", "c:\\", SW_SHOWNORMAL);
ShellExecuteEx (&sei);
return 0;
}
----------
Here are the error messages:
----------
c:\program files\microsoft visual studio\vc98\include\shellapi.h(53) : error C2065: 'HDROP' : undeclared identifier
c:\program files\microsoft visual studio\vc98\include\shellapi.h(53) : error C2501: 'DECLARE_HANDLE' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\shellapi.h(55) : error C2146: syntax error : missing ';' before identifier 'UINT'
c:\program files\microsoft visual studio\vc98\include\shellapi.h(55) : error C2501: 'DECLSPEC_IMPORT' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\shellapi.h(55) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
LoadHtml.exe - 5 error(s), 0 warning(s)
----------
Can you help?
regards,
Geo
|
|
|
|
|
The documentation doesn't explicitly say so, but shellapi.h has dependencies on the Windows base headers. Include windows.h before any other Windows headers.
|
|
|
|
|
|
Hi!
when I exports a class where I mixed managed and undmaged code and in an another dll try to use the exported class (declared as 'gcroot<cdedusetpdb*> m_SetPDB;' ) I receive the following error when compileing. Why?
I have compiled with option /clr.
DAkut error LNK2020: unresolved token (06000065) CDeDUSetPDB::.ctor
DAkut error LNK2020: unresolved token (06000066) CDeDUSetPDB::Finalize
DAkut error LNK2020: unresolved token (06000067) CDeDUSetPDB::Login
The exported class look like this:
#pragma once
#ifdef IMPL_DPDB
#define CLASS_DECL_DPDB _declspec(dllexport)
#else
#define CLASS_DECL_DPDB _declspec(dllimport)
#endif
#include <afx.h>
#using <mscorlib.dll>
#include <vcclr.h>
#using <system.dll>
#using <system.data.dll> // This is required for the ADO.NET Provider
#using <system.web.services.dll>
#using "c:\Inetpub\wwwroot\DeDUWebService\bin\DeDUWebService.dll"
using namespace System::Runtime::InteropServices;
using namespace System::Web::Services;
using namespace DeDUWebService;
// CDeDUSetPDB
class CLASS_DECL_DPDB CDeDUSetPDB : public CObject
{
// DECLARE_SERIAL(CDeDUSetPDB)
private:
short m_nValue;
public:
// uncomment the lines below to avoid the compiler errors
CDeDUSetPDB() {};
CDeDUSetPDB( const CDeDUSetPDB &s ) // copy ctor
{ m_nValue = s.m_nValue; }
CDeDUSetPDB& operator=( const CDeDUSetPDB &s ) // assignment operator
{ m_nValue = s.m_nValue; return *this; }
// Loggar in på DeDU Databas
int Login(char* szNamn, char* szPwd)
{ return ws->Login(szNamn,szPwd); }
protected:
gcroot<deduservice*> ws;
};
MSc Bertil Morefält
|
|
|
|
|
if you wanted to use a managed object
you will need to declare your class like
__gc class Someclass //to indicate the class is garbage collectable.
hope this helps.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
I tried that.
I want to export the hole class so
I declared the class like this
_gc class _declspec(dllexport) Someclass // The compile dosn't allow it.
Why?
MSc Bertil Morefält
|
|
|
|
|
If your managed class in already in DLL form which is a assemblies. You can straight up to utilize it in C#, VB.NET , J# and etc.
But if you like to consume a managed component from an unmanaged. You will need to export the assembly hosting the managed component into a COM type library, which an unmanaged, COM-aware client.
The command of generating the TLB is as follow
> regasm YourManaged.dll /tlb:YourManaged.tlb
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
We are running our c++ program as Windows services which uses JNI, . Program is getting CLASSPATH env variable correctly and also initializes JVM successfully. After initializing JVM, programs makes a JNI call FindClass() for getting java class.But FindClass method returns NULL even though java class exists in the CLASSPATH.
Same program when is run from command window, FindClass method call is working fine.
Is there any difference between running a program thru command window and as a windows service ?
Incase you have any idea on how to resolve this issue, kindly get back ASAP.
Best Regards,
sarathy
|
|
|
|
|
As a Windows service, your code is running under a different security context - for example, it is not an interactive user, it's running in a service logon. The difference here is that as an interactive user your process token includes the INTERACTIVE Security Identifier (SID), whereas as a service it instead includes the SERVICE SID.
The difference in SIDs or user accounts might lead to an access-denied error if the Access Control List on your class file is too strict. I suggest using SysInternals FileMon to investigate. See the SysInternals NT tools page[^].
|
|
|
|
|
i want to add an icon to a tree control but i can't. please tell me how can i do it .which section of this code is wrong?
CTreeControl m_tree;
CImageList img;
HICON hicon;
hicon=LoadIcon(IDR_MAINFRAME);
img->Add(AfxGetApp()->hicon);
m_tree.SetImageList(img, TVSIL_NORMAL);
|
|
|
|
|
First thing:
The SetImageList-call wants the pointer to an imagelist - but maybe that is a typo, as the compiler would be telling you that clearly.
Second thing:
Is it OK to let the ImageList-object you just introduced to the TreeCtrl go out of scope?
Maybe you need to make it a member?
Here is what I do (but note that I fill the imagelist with bitmaps!):
m_TreeImageList.DeleteImageList();
if(m_TreeImageList.Create(16,16,ILC_MASK,8,0))
{
std::vector<unsigned int> bmpId;
bmpId.push_back(IDB..);
bmpId.push_back(IDB..);
[...]
CBitmap bmp;
m_TreeImageList.SetBkColor(GetSysColor(COLOR_WINDOW));
for(unsigned int i = 0; i < bmpId.size(); ++i)
{
int b = bmp.LoadBitmap(bmpId[i]);
b = m_TreeImageList.Add(&bmp,(COLORREF)0xFFFFFF);
bmp.DeleteObject();
}
}
else
{
AfxMessageBox("ImageList Creation Failed!");
}
m_MyTree.SetImageList(&m_TreeImageList, TVSIL_NORMAL);
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
In addition to parameter one of SetImageList() needing to be a pointer, I'm not sure what you are trying to do with
img->Add(AfxGetApp()->hicon);
Clearly, CWinApp does not have a member named hicon, so I can only assume you meant
img->Add(hicon);
instead.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
hi ,
how can i get all of the computer name&ip in local net work .I want to get other computer names&ip (All) ? how can i do ? do you understand me ? Can you help me ?
thank you !
|
|
|
|
|
my little suggestions:
char szhostname[128];
//gethostname
if( gethostname(szhostname, 128) == 0 )
{
// get ipaddr.
struct hostent * phost;
phost = gethostbyname(szhostname);
}
//and refer to msdn
Hello World!
|
|
|
|
|
not only my computer name & ip ! all in then local network .(some groups in the network)
|
|
|
|
|
i guess it's what about WNetOpenEnum.
See msdn.
Hello World!
|
|
|
|
|
see:
// TODO: Add extra validation here
CString strTemp;
struct hostent *host;
struct in_addr *ptr; // To retrieve the IP Address
DWORD dwScope = RESOURCE_CONTEXT;
NETRESOURCE *NetResource = NULL;
HANDLE hEnum;
WNetOpenEnum( dwScope, NULL, NULL,
NULL, &hEnum );
WSADATA wsaData;
WSAStartup(MAKEWORD(1,1),&wsaData);
if ( hEnum )
{
DWORD Count = 0xFFFFFFFF;
DWORD BufferSize = 2048;
LPVOID Buffer = new char[2048];
WNetEnumResource( hEnum, &Count,
Buffer, &BufferSize );
NetResource = (NETRESOURCE*)Buffer;
char szHostName[200];
unsigned int i;
for ( i = 0;
i < BufferSize/sizeof(NETRESOURCE);
i++, NetResource++ )
{
if ( NetResource->dwUsage ==
RESOURCEUSAGE_CONTAINER &&
NetResource->dwType ==
RESOURCETYPE_ANY )
{
if ( NetResource->lpRemoteName )
{
CString strFullName =
NetResource->lpRemoteName;
if ( 0 ==
strFullName.Left(2).Compare("\\\\") )
strFullName =
strFullName.Right(
strFullName.GetLength()-2);
gethostname( szHostName,
strlen( szHostName ) );
host = gethostbyname(strFullName);
if(host == NULL) continue;
ptr = (struct in_addr *)
host->h_addr_list[0];
// Eg. 211.40.35.76 split up like this.
int a = ptr->S_un.S_un_b.s_b1; // 211
int b = ptr->S_un.S_un_b.s_b2; // 40
int c = ptr->S_un.S_un_b.s_b3; // 35
int d = ptr->S_un.S_un_b.s_b4; // 76
strTemp.Format("%s --> %d.%d.%d.%d",
strFullName,a,b,c,d);
AfxMessageBox(strTemp);
}
}
}
delete Buffer;
WNetCloseEnum( hEnum );
}
WSACleanup();
//*******************************************
I try ,but fail ! thanks all the same !
|
|
|
|
|
Hellin wrote:
I try ,but fail !
Which tells us nothing. What exactly is failing? Are you getting a compiler/linker error. Is an assertion firing? Have you stepped through the code to see exactly what is (not) happening?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
not code Error ,I say that ,only can search my own computer name &ip ,so i say I fail to !
|
|
|
|