|
It's amazing how little information on this there is out there. But any way, I'm just trying to create a standard IP port. I'm using Windows XP, I assume this code would behave the same on 2000 but haven't tried it.
I have looked at MSDN and tried to follow the documentation, but it is either incomplete or incorrect, or I'm just doing something wrong. Here is how I'm trying to create a new port.
The problem is that XcvData always fails and GetLastError returns 87 (invalid parameter.) I have no idea which parameter might be invalid, or why. I have also tried deleting a port, similarly following the documentation, and it fails as well. What's going on?
void AddMeAPort()
{
HANDLE hXcv = INVALID_HANDLE_VALUE;
PRINTER_DEFAULTS Defaults = {NULL, NULL, SERVER_ACCESS_ADMINISTER};
PORT_DATA_1 info;
::ZeroMemory(&info, sizeof(PORT_DATA_1));
DWORD error = 0;
_tcscpy(info.sztPortName, _T("MyPort"));
info.dwVersion = 1;
info.dwProtocol = PROTOCOL_RAWTCP_TYPE;
info.cbSize = sizeof(PORT_DATA_1);
_tcscpy(info.sztHostAddress, _T("some.host.name"));
_tcscpy(info.sztSNMPCommunity, _T("public"));
info.dwPortNumber = 9100;
info.dwSNMPEnabled = 1;
info.dwSNMPDevIndex = 1;
if(::OpenPrinter(_T(",XcvMonitor Standard TCP/IP Port"), &hXcv, &Defaults))
{
BYTE *hackedData = reinterpret_cast<BYTE *>(&info);
DWORD status = 0;
if(::XcvData(hXcv, L"AddPort", hackedData, sizeof(PORT_DATA_1), NULL, 0, NULL, &status))
{
} else
{
error = ::GetLastError();
}
::ClosePrinter(hXcv);
} else
{
error = ::GetLastError();
}
}
"When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein
|
|
|
|
|
Well, I figured it out on my own... the documentation is misleading. It says you can pass NULL to the second-to-last parameter for XcvData, but that's wrong, you need to pass in a pointer to a DWORD. Go figure.
"When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein
|
|
|
|
|
Good people,
I’ve tried the following C++ console application sample under MS DevStudio 2003:
#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
for (int index = 0; index < 3; ++index)
{
std::cout << index << std::endl;
}
std::cout << index << std::endl; // should yield a compiler error
return 0;
}
The assumption was that the commented line shouldn’t compile because it tries to access the index variable, which is out of the scope (its scope is the for loop, according to C++ standard). I need to refer to the Microsoft’s non-conformance issues on this topic, but couldn’t find one. I would much appreciate if you could provide me the link to this topic.
Thanks,
Serge
|
|
|
|
|
It's quite simple, actually. IF you go under your project's "Properties" tab, there is a setting about this issue.
Go to the C/C++ tree folder, and in it, the Language item.
There is an item in the right called "Force conformance in For Loop Scope". You can turn it on, in which case the above code you had will fail to compile, or leave it off, in which the code will compile. For whatever reason, it is set to "no" by default, perhaps for compatibility with older code?
But that's what you want.
I hope that answers your question...
"When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein
|
|
|
|
|
Thanks !!!
So, can I assume that there is no _official_ non-conformance issue on this topic?
Thanks,
Serge
|
|
|
|
|
Yes, there are official documents that talk about conformance issues. I don't know how in depth they might be.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Tim,
I need a link to that document.
Thanks,
Serge
|
|
|
|
|
i want a function to do the following .
open a text file ..
check for a string given as input parameter to the function whether it is available in the text file .
return the string after = sign in the text file .
for example the text file may contain data as below
proj1=customer
proj2=report
proj3=client
if i call the function passing proj2 as parameter then it should return report and if pro4 is sent as parameter it should return failed/not found.
thanx in advance
|
|
|
|
|
My solution (which is not the only nor effecient one) would be make a CStdioFile, open the file, use the ReadString to put a line in a var (strLine). Take out the first x amount of characters (x being the Len(parameter)). Compare that var with the parameter, if equal then use strLine.Right(len(strLine) - (len(parameter) + 1)) to return your 'report', 'client', etc.
if don't find any, when reach EOF, just display 'failed/not found'.
ja
|
|
|
|
|
Sounds like you are looking for a setup file.
There are heaps of articles on CodeProject to do this. You could possibly try something like IOBind.
If you have to do it your way you could try (in no particular order)
1/ boost::spirit, which is a metatemplate parser
2/ lex or flex, which are parsers
3/ use something like Lua, which is a scripting language which lets you get / set variables from a script
4/ use an XML parser (assuming you really do want a setup file) - maybe tinyXML
5/ use raw STL, iostreams, strings and string::find()'s
6/ use STL with boost::regex
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
or you could do it a simple way unless i'm missing some huge thing...
- input the string from the text file
- check to see if the first character of the string is NULL
- check to see if any of the characters in the string are '='
- if the above is true, put every character after the = sign inside a new string
- do what you need to do with that new string
*.*
cin >> knowledge;
|
|
|
|
|
CString strSearch = "proj1";
CString strLine;
CString strValue;
CStdioFile file;
while (file.ReadString(strLine) == TRUE)
{
if (strLine.Find(strSearch + '=') != -1)
{
strValue = strLine.Mid(strLine.Find('=') + 1);
break;
}
}
|
|
|
|
|
void CMyDlg::OnEndlabeleditList(NMHDR* pNMHDR, LRESULT* pResult) <br />
{<br />
LV_DISPINFO *plvDispInfo = (LV_DISPINFO *)pNMHDR;<br />
LV_ITEM *plvItem = &plvDispInfo->item;<br />
<br />
AfxMessageBox("Hello");<br />
<br />
*pResult = FALSE;<br />
}<br />
<br />
void CMyDlg::OnButton1()<br />
{<br />
}
I want to run all code lines in CMyDlg::OnEndlabeleditList() when I click to Button1
such as to display a messagebox "Hello"
I dont know how to do it
help me
thanks
|
|
|
|
|
Hi,
In the message map you have to have something like this:
BEGIN_MESSAGE_MAP(...)
...
ON_MESSAGE(999,OnEndlabeledList)
...
END_MESSAGE_MAP()
And in your OnButton1 function you have to
SendMessage(999);
-----
We are what we repeatedly do. Excellence, then, is not an act, but a habit.
|
|
|
|
|
Florin Ochiana wrote:
SendMessage(999)
At least try something like
#define MAGIC_MESSAGE WM_APP+99 (or some other number)
ON_MESSAGE(MAGIC_MESSAGE,OnEndlabeledList)
...
SendMessage(MAGIC_MESSAGE);
MSDN states:
Message numbers in the first range (0 through WM_USER – 1)
are defined by the system. Values in this range that are not explicitly
defined are reserved for future use by the system. WM_USER is defined to be 0x400, so that your value of 0x3E7 (deimal 999) would send some message you did never intend to send to your window.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
2 ways to do this. Easy way: you can break out the relevant code from the OnEndlabeleditList handler into its own public function, and simply call that, e.g.;
void CMyDlg::OnButton1()
{
CallSomeFunction();
}
Or you can, as you were trying to do, use SendMessage. You will need the window handler of the listbox window, or a listbox class, and call SendMessage on it and send it the appropraite message. If you look at the list box (or is it a list control??) documentation in MSDN you can find the right message. It'll look like one of these:
HWND hListWindow = ::GetDlgItem(ITEM_ID_FROM_RC_FILE);
::SendMessage(hListWindow, message_id, wparam, lparam);
theListCtrl.SendMessage(message_id, wparam, lparam);
"When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein
|
|
|
|
|
Hello, I have a problem with my MDI. When the CWinApp constructor
is called in my program several initializes are skipped. Inside
the appcore.cpp that houses the initialization code I have placed a
break point where the initialization begins. When I step through
after the 'ASSERT(AfxGetApp() == this);' line, the code jumps to
the section called '// other initialization'. The break point for the initialization code has a question mark (?) inside of it.
So when I go to close my file and the CWinApp destructor is called,
I get an error. When I make a release of it and put it on another
computer without Visual Studio, the program doesn't start. (But it
does starts on the two computers with Visual Studio 7 and 5)
What do I do to get this to work? Please help me, I need to turn
this project in my Aug 15. Thanks.
By the way, I tried it making a new mdi and the code is not skipped
on that one, but I have followed the initialization for that.
|
|
|
|
|
pdunn wrote:
By the way, I tried it making a new mdi and the code is not skipped
on that one, but I have followed the initialization for that.
That statement makes very clear that you accidentially messed something up with your class.
We need now to find out what exactly.
What are you doing in the Apps constructor that should not better be done in InitInstance()?
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
unfortunately, that's wrong. The CWinApp constructor is called before the CWinApp::InitInstance(). CMyWinApp constructor is blank like the new mdi. I put it in there before I found that out. I nor MFC ever calls CWinApp(), but it does execute. Now I need to know why is part of the code in that method is being skipped.
Thanks for the effort.
|
|
|
|
|
pdunn wrote:
The CWinApp constructor is called before the CWinApp::InitInstance().
That is the way it is meant to be.
pdunn wrote:
CMyWinApp constructor is blank like the new mdi.
Good! Only some member variable initialisations belong there.
pdunn wrote:
I nor MFC ever calls CWinApp(), but it does execute.
It is called while instantiating the one global instance of your application.
Look for the line CYourApp NEAR theApp; in your apps header.
pdunn wrote:
Now I need to know why is part of the code in that method is being skipped.
Place a breakpoint on your line CYourApp NEAR theApp; line.
Place another breakpoint on the first line of your InitInstance().
'F11' should take you right to the beginning of your (empty, as you said) app constructor.
Hitting 'F5' brings you to the breakpoint at the beginning of the InitInstance().
Where does your error come up?
BTW - You did a clean rebuild of your application?
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
Thanks for the reply.
My code is not being skipped. It is the MFC, appcore.cpp. The (+) denotes where I placed a break point.
CWinApp::CWinApp(LPCTSTR lpszAppName)
{
(+) if (lpszAppName != NULL)
m_pszAppName = _tcsdup(lpszAppName);
else
m_pszAppName = NULL;
// initialize CWinThread state
AFX_MODULE_STATE* pModuleState =
_AFX_CMDTARGET_GETSTATE();
AFX_MODULE_THREAD_STATE* pThreadState =
pModuleState->m_thread;
ASSERT(AfxGetThread() == NULL);
pThreadState->m_pCurrentWinThread = this;
ASSERT(AfxGetThread() == this);
m_hThread = ::GetCurrentThread();
m_nThreadID = ::GetCurrentThreadId();
// initialize CWinApp state
ASSERT(afxCurrentWinApp == NULL);
// only one CWinApp object please
pModuleState->m_pCurrentWinApp = this;
ASSERT(AfxGetApp() == this);
// in non-running state until WinMain
(+) m_hInstance = NULL;
m_hLangResourceDLL = NULL;
m_pszHelpFilePath = NULL;
m_pszProfileName = NULL;
m_pszRegistryKey = NULL;
m_pszExeName = NULL;
m_pRecentFileList = NULL;
m_pDocManager = NULL;
m_atomApp = m_atomSystemTopic = NULL;
m_lpCmdLine = NULL;
m_pCmdInfo = NULL;
...}
The second breakpoint at 'm_hInstance = NULL;' never gets called because that is where the code skips causing 'm_pDocManager' not to get initialize. Thus when the program is closed, an error occurs because the program is trying to delete an uninitialized pointer.
The value inside of m_pDocManager is junk. Furthermore, the second breakpoint has a '?' (question mark) inside of it. I don't know what this means.
Thus the error does not come from the initInstance like I first thought but the constructor of CWinApp.
|
|
|
|
|
pdunn wrote:
My code is not being skipped. It is the MFC, appcore.cpp
[Sound like Fangorn from LOTR]
HoHum
[/Sound like Fangorn from LOTR]
I have never had to step through that file.
The only thing I can think of is that the code file you are looking at is different from the one that the debug info used for stepping is made from.
Anything I can think of is wild guessing, sorry!
Are you perchance mixing MFC versions? Compilers (like VC++6 and VC++7 or VC++2003)?
In the 'project settings/debug' the line 'Executable for debug sessions' points to the correct .EXE?
You do link a 'debug multithreaded' library?
You let the compiler generate a 'Browse info' and a 'Program Database'?
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
I would like to have a sourcecode to automatically discover the computers in my LAN/Domain and execute a a program remotely to all the computers it discovers. This code should be able to list all the computers it found and if we right click on any computer name, it have an option to remotely execute the program mentioned. Can anyone help? I am not a good programmer and seeking you guys help to accomplish my task.
|
|
|
|
|
Don't they call this kind of application a worm?
Clickety[^]
Steve S
|
|
|
|
|
Steve,
They may call this a worm but my intention is to discover the PCs in the network and do a software and hardware inventory. Many software out there is being excutable using logon scripts and it is time consuming. Microsoft has a tool to check the network for any softwares installed and I do not how the mechanism works. So does the SMS Server do...Network Discovery. So, If I can have a source codes how to do this then I can write the program that will retrieve the information needed. Rgds,
|
|
|
|