|
First off, I would like to thank you for taking the time to see this problem. I'm sort of a n00b when it comes to using COM objects, and unfortunately the way I'm learning has a really steep learning curve. Basically, I am trying to create a program that writes to Word, and I'm having a bit of a problem passing objects to the COM objects that I instantiate - specifically the Range and Section objects. So let me order my questions:
1) How do I correctly create a new Range object so I can add it to a Section object?
2) How do I add the Range object to the Section? (According to the VBA documentation, the Sections collection object has an Add method that takes a Range object as its first argument [MFC specifies it as a VARIANT parameter type] and placement as a second argument).
Basically this is the way I see it, but I don't know how to do it:
1) Create new Range object.
2) Set information in Range object.
3) Add new Section using Sections.Add(new_range_obj, placement)
If anybody has any code that I can look at in an existing solution that interfaces with Word that would be awesome. I usually learn better by looking at code and seeing what it does anyways. Thanx!
|
|
|
|
|
Hi folks,
Where i can find the diference between C++ and VC++?.
Please send me link or material.
|
|
|
|
|
The main difference between regular C++ and Visual C++ is just that Visual C++ works a lot with Microsoft's frameworks, specifically .NET (if its Visual C++.NET) and MFC. You can still write standard C++ applications in VC++ with/without the Microsoft frameworks, however getting the Microsoft frameworks to work with other IDEs is difficult, yet possible if you really know how to do it. Microsoft does not release it's MFC framework, so in order to use it you would have to get VC++. In terms of IDE, its a matter of preference, otherwise its purely what you can and can not do between C++ and VC++. Just remember, everything you do in VC++ you could do in standard C++, but it would just take longer because you don't have all the pre-defined objects for Windows development that Microsoft provides as part of VC++.
Hope that helps.
|
|
|
|
|
C++ is a programming language, Visual C++ is a compiler/IDE for the C++ programming language.
|
|
|
|
|
The thing is that C++ is the language, and VC++ is just the environment that you can program in C++. It is like writing English text in Notepad- the language is English, but you write it in Notepad. But you can also write it in Word, WordPad? and so on... so, VC++ is the program(IDE to be more certain), and C++ is the language.
I hope you got it!
keep smilling.....b'coz smile is the shortest distance between people....
|
|
|
|
|
Difficult question! VC++ and C++ are the same thing, the differences lay in what non-standard C++ keywords are specific to the MS-VC++ compiler. Other C++ compilers also have there own non-standard keywords. You can look up MS-VC++ specific keywords in the MSDN library, also many you will see many places in MSDN that state "Microsoft specific", which apply either to keywords of compiler specific instructions.
Your best bet is to get a book on standard C++, like those written by the origanal author of C++ Bjarne Stoustrup or maybe P.J. Plauger (former member of the standards commitee). Once you know what is standard C++, then you will beable to see what is not standard in VC++.
Another source of information are articles on cross platform programming, and also cross platform libraries (there are some at sourceforge.net, as a matter of fact there are lots of projects at sourceforge.net that are cross platform).
P.S. not all compilers are standards compliant, so just because the standard says something is so, does not mean that it is so for a given compiler.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Hi folks-
I've been searching for answers on this problem for days. Hope someone can help!!
I've got a very basic example application, taken directly from the WinInet HttpSendRequestEx() example on MSDN (http://support.microsoft.com/kb/q177188/). I have to use this function in my appication since a large amount of data must be sent.
My test program works perfectly except when Digest authentication and SSL are being used. In that case only, the call to InternetErrorDlg() raises an access violation exception inside the Wininet DLL.
No SSL works fine. Basic authentication works fine. SSL with Basic Authentication works fine. No SSL with Digest works fine!!!
I'm testing with a free Proxy server called FreeProxy, the only one I could find which supports both Basic and Digest authentication.
I discovered that the HTTP Status code must be checked right after the call to HttpSendRequestEx() (see the code). Code 407 (Proxy authentication required) is returned here when the proxy is running and the next call to InternetWriteFile() will fail.
One other thing I observed is that when using Digest the last call to InternetReadFile() (at the end) to retrieve the response hangs up for about 30 seconds before finally returning normally. This does not happen with Basic authentication.
So the question is... what is causing that access violation inside WinInet when I call InternetErrorDlg()???? Have tried this on Win 2000 and XP.
Also, if anyone knows of another authenticating proxy I can test with that would be great.
Thanks!!
-Nicholas
Here's my code:
BOOL bSecure = TRUE;
HINTERNET hConnect;
if (!bSecure)
hConnect = InternetConnect(hSession, "server.com", INTERNET_DEFAULT_HTTP_PORT,
NULL, NULL, INTERNET_SERVICE_HTTP,NULL, NULL);
else
hConnect = InternetConnect(hSession, "server.com", INTERNET_DEFAULT_HTTPS_PORT,
NULL, NULL, INTERNET_SERVICE_HTTP,NULL, NULL);
HINTERNET hRequest;
if (!bSecure)
hRequest = HttpOpenRequest(hConnect, "POST", "test.cgi",
NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
else
hRequest = HttpOpenRequest(hConnect, "POST", "test.cgi",
NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_SECURE, 0);
INTERNET_BUFFERS BufferIn;
DWORD dwBytesWritten;
int n;
BYTE pBuffer[1024];
BOOL bRet;
BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS ); // Must be set or error will occur
BufferIn.Next = NULL;
BufferIn.lpcszHeader = NULL;
BufferIn.dwHeadersLength = 0;
BufferIn.dwHeadersTotal = 0;
BufferIn.lpvBuffer = NULL;
BufferIn.dwBufferLength = 0;
BufferIn.dwBufferTotal = dwPostSize; // This is the only member used other than dwStructSize
BufferIn.dwOffsetLow = 0;
BufferIn.dwOffsetHigh = 0;
if(!HttpSendRequestEx( hRequest, &BufferIn, NULL, 0, 0)) {
printf( "Error on HttpSendRequestEx %d\n",GetLastError() );
return FALSE;
}
BOOL bHaveProxy = FALSE;
// get the http status code (if any)
DWORD dwStatusCode;
DWORD dwLength = sizeof(dwStatusCode);
if (HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwStatusCode, &dwLength, NULL) &&
dwStatusCode == 407)
bHaveProxy = TRUE; // we're connecting thru an authenticating proxy server
if (!bHaveProxy) { // call to InternetWriteFile() will fail with code 12019 if we got 407
FillMemory(pBuffer, 1024, 'D'); // fill buffer with meaninless data
bRet=TRUE;
for(n=1; n<=(int)dwPostSize/1024 && bRet; n++) {
if(bRet=InternetWriteFile( hRequest, pBuffer, 1024, &dwBytesWritten))
printf( "\r%d bytes sent.", n*1024);
}
if(!bRet) {
printf( "\nError on InternetWriteFile %lu\n",GetLastError() );
return FALSE;
}
}
if(!HttpEndRequest(hRequest, NULL, 0, 0)) {
printf( "Error on HttpEndRequest %lu \n", GetLastError());
return FALSE;
}
// get the http status code (if any)
dwLength = sizeof(dwStatusCode);
if (HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
&dwStatusCode, &dwLength, NULL) && dwStatusCode == 407)
bHaveProxy = TRUE;
// show the proxy login dialog if a proxy was detected (code 407)
if (bHaveProxy) {
// note: this call causes an access violation if using SSL with Digest authentication
InternetErrorDlg(GetDesktopWindow(), hRequest, ERROR_SUCCESS,
FLAGS_ERROR_UI_FILTER_FOR_ERRORS | FLAGS_ERROR_UI_FLAGS_GENERATE_DATA |
FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS, NULL);
}
// read response
DWORD dwBytesRead;
char pcBuffer[512];
printf("\nThe following was returned by the server:\n");
do {
dwBytesRead=0;
if (InternetReadFile(hRequest, pcBuffer, 511, &dwBytesRead)) {
pcBuffer[dwBytesRead]=0x00; // Null-terminate buffer
printf("%s", pcBuffer);
} else
printf("\nInternetReadFile failed");
} while (dwBytesRead>0);
|
|
|
|
|
Why do i get a critical error here in this code. I want to read succesive pages in a process memory
<br />
int main(int argc, char **argv[]) <br />
{<br />
PROCESS_INFORMATION pi; <br />
STARTUPINFO si; <br />
HANDLE hProcess; <br />
BYTE buf[200000]; DWORD bufsize = sizeof buf;<br />
DWORD baseaddr = 0;<br />
LPCVOID lpAddress = 0;<br />
PMEMORY_BASIC_INFORMATION lpBuffer = 0;<br />
DWORD dwLength = 0;<br />
DWORD flNewProtect =0;<br />
PDWORD lpflOldProtect = 0;<br />
DWORD dwSize =0;<br />
LPCVOID lpBaseAddress = 0;<br />
DWORD nSize = 0;<br />
DWORD buff = 0;<br />
LPDWORD lpNumberOfBytesRead = sizeof buf;<br />
if (argc !=2)<br />
{<br />
printf("Error in the input line, Usage: Inputfile");<br />
exit(0);<br />
}<br />
<br />
printf("Process %d creates a child process\n",GetCurrentProcessId());
GetStartupInfo(&si);<br />
<br />
CreateProcess(NULL,<br />
argv[1], NULL, <br />
NULL, <br />
FALSE, CREATE_NEW_CONSOLE, <br />
NULL, <br />
NULL, <br />
&si, <br />
&pi <br />
);<br />
hProcess = pi.hProcess; <br />
printf("New Process ID: %d ",pi.dwProcessId);<br />
printf("has started \n");<br />
<br />
VirtualQueryEx(<br />
hProcess,
lpAddress,
lpBuffer,
dwLength,
GetLastError()<br />
);<br />
VirtualProtectEx(<br />
hProcess,
lpAddress,
dwSize,
flNewProtect,
lpflOldProtect );
<br />
ZeroMemory(buf, sizeof(buf));<br />
if( ReadProcessMemory( hProcess, lpBaseAddress, nSize, bufsize, buff ) == FALSE )<br />
{<br />
printf("\nProcess ID %d ",pi.dwProcessId);<br />
printf (" memory read failed (errcode: %d)", GetLastError());<br />
printf("\nmemory read: \n",&buf);<br />
}<br />
else<br />
{<br />
printf("\nProcess ID %d ",pi.dwProcessId);<br />
printf("memory read: \n",buf);<br />
}<br />
return (0);<br />
}<br />
oam
|
|
|
|
|
Well to start with you can not do things like this:
LPDWORD lpNumberOfBytesRead = sizeof buf;
The variable lpNumberOfBytesRead is a pointer and a pointer holds the address of where the data is stored. What the above line is doing is setting the address to the value sizeof(buf), which is not an address.
Change to:
DWORD NumberOfBytesRead = sizeof(buf);
or this (since its initial value may not matter)
DWORD NumberOfBytesRead = 0;
and pass like this
SomeFunction(...,...,&NumberOfBytesRead);
Now the following from your code, should make any C++ compiler choke (fail with errors):
ReadProcessMemory(
hProcess,
lpBaseAddress,
nSize, // This should be a pointer to buffer
bufsize,
buff ); // This should be a pointer to DWORD
The correct arguments are
ReadProcessMemory( hProcess, lpBaseAddress, buf, bufsize, &NumberOfBytesRead);
or
ReadProcessMemory( hProcess, lpBaseAddress, buf, sizeof(buf), &NumberOfBytesRead);
I have no doudt that there are several other things wrong with this code, but the above should help you get started on figuring out what they are.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Yep i looked at that and there were mistakes, but the main problem comes from the virtualqueryEx function which has to do most of the things. Because i have to read pages using it...
So it gives this error msg:
"The value of ESP was not properly saved across a function call."
error code 5: Illegal function call
error code 998: from virtualqueryex function
oam
|
|
|
|
|
The code you gave should not compile on any compiler period! Let alone give any error messages when run. I can not remember ever seeing so many basic programming errors. If by some miricle it did run, then (Yep) it would probubly crash. Heck you stand a better chance of crashing the whole system than making that code work (as written).
As for VirtualQueryEx: Why are you even trying to call it? The call appears to be used to retrieve information that needs to be stored in the structure pointed to by lpBuffer, but lpBuffer does not point to a structure, it points to NULL. The only reason the dwLength argument is correct, is that it is 0, since lpBuffer is NULL. You are also passing it a 5th argument GetLastError, for who knows what reason (it only takes 4 arguments and this is not one of them).
I recomend you start all over again from scatch. What ever it is you are trying to accomplish, this will not do it.
P.S. Sorry but if I was an employer, the code you gave would get you fired.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
See title , thanks..
Couldn't find the functions using MSDN or google .
|
|
|
|
|
GetFileAttributes(), check the FILE_ATTRIBUTE_DIRECTORY bit.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
bool dirExists
(CString strDirectory)
{
TCHAR* fullPath = _tfullpath (NULL, strDirectory, 0);
if (fullPath == NULL)
return (false);
TCHAR szCurrDir [_MAX_PATH];
_tgetcwd (szCurrDir, _MAX_PATH - 1);
long nStatus = _tchdir (fullPath);
_tchdir (szCurrDir);
free (fullPath);
if (nStatus == 0)
return (true);
return (false);
} /ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
|
We have a driver for low level control for the parallel port using outp inp. However, this driver only works on NT platforms under Administrator. I am trying to find a way to tell the manager that the user has permissions to run this driver.
However, I cannot get access to the manager from my level to do that. How can I change the rights for the program to run under any user?
here is a snipit of code that I have.
// connect to local service control manager
if ((m_hSCMan = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == NULL)
{
AfxMessageBox("Can't connect to service control manager\n\nI am assuming that you are working on a non-NT system.\n\nIf not you will need to investigate the problem", MB_OK);
m_fNT = FALSE;
}
else
{
if (DriverStart(szDriver))
{
AfxMessageBox("Unable to start the driver!\n\n"
"Please try running [loaddrv] to correct this issue.", MB_OK);
}
}
|
|
|
|
|
in my app, i open a html file and get its buffer in memory, is it possible to display the file buffer as a normal html page?
the html file is inside a zipped file, so it can not be desplayed directly.
thanks
includeh10
|
|
|
|
|
includeh10 wrote:
is it possible to display the file buffer as a normal html page?
Yes. See this[^] article.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hello.
my problem is that i'm loading a dll to extract some data but it gets lost when i unload the library, i have the following struct
<br />
struct tagPLUGIN{<br />
PCHAR Name;<br />
PCHAR FileName;<br />
UINT Category;<br />
UINT Vital;<br />
ULONG Id;<br />
UINT isUI; <br />
};
and from my main exe i just load the library, get the proccess address and call a dll function to fill the structure
<br />
extern "C" __declspec(dllexport) void GetPlugInfo (tagPLUGIN *plugin)<br />
{<br />
<br />
AFX_MANAGE_STATE(AfxGetStaticModuleState());<br />
plugin->Category=TOOL;<br />
plugin->Id=0;<br />
plugin->isUI=TRUE;<br />
plugin->Name=new char[25];<br />
strcpy(plugin->Name,"Configuración de Sistema\0");<br />
plugin->Vital=FALSE;<br />
}<br />
loading the dll
<br />
tagPLUGIN plugin;<br />
typedef void (*GetPlugInfo)(tagPLUGIN *info);<br />
HMODULE dll=LoadLibrary(tmp_string);<br />
GetPlugInfo getPlugInfo = (GetPlugInfo)GetProcAddress(dll,"GetPlugInfo");<br />
(getPlugInfo)(&plugin);<br />
plugin.Id=ID++;<br />
plugin.FileName=new char[tmp_string.GetLength()+1];<br />
strcpy(plugin.FileName,tmp_string.GetBuffer());<br />
FreeLibrary(dll);<br />
but right after FreeLibrary(dll) my two PCHAR values are corrupt, i know the problem is in the new char[size] , so how can i pass a PCHAR to a dll function and allocate and assign a string without loosing it after freelibrary?
|
|
|
|
|
you could do the allocation in the calling module, not in the DLL. or, just use a fixed-size buffer for the text in the structure.
or, use global memory (ie. GlobalAlloc, etc) to allocate the strings.
Image Toolkits | Image Processing | Cleek
|
|
|
|
|
Hi Chris,
no it doesn't, i was trying to with HeapAlloc, but both after i call FreeLibrary(dll)
i get a <bad ptr=""> value.
By the way, why it works in debug mode?
anybody can give me links of dll tutorials/guides please.
Best Regards
|
|
|
|
|
Your dll, and or exe, is likely being staticly linked to the CRT.
That is, the dll new, malloc, alloc, calloc functions are using a heap local to the dll.
When the dll is unloaded the heap is destroyed.
The debug version is likely set to dynamicly link to the CRT so the exe and dll use the same heap for memory allocations.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Tthanks for your help.
No, i'm using both debug and release in shared dll, the dll and exe both debug uses debug and release uses release, i've tried, new,malloc,GlobalAlloc and Heap Alloc, same result.
i'll do some more reading about dlls and retry this, but for now i have an idea, can you tell me if this could be the good way:
near that code i have some code to read from the registry and i've noted that when in RegQueryValueEx you pass a buffer too small for the required data (REG_SZ) it returns the size of the buffer needed so you can reallocate the memory for the buffer with that size, so i'll code my GetPlugInfo in that way and i'll pass the PCHAR vars with the memory preallocated. Is that a good solution?
Thanks in advance.
|
|
|
|
|
I'm not sure that you understood what i was talking about.
In VC++
Goto Projects - Settings.
Goto C/C++ - Code Generation.
For both your exe and dll the 'Use run-time library' should be:
'Debug Multithreaded DLL' for your debug builds.
and
'Multithreaded DLL' for your release builds.
There is no reason you can't do what you originally specified.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Hi,
I want to use arrow key to move focus among dialog controls. But standard dialog does not support this. How can i do it? is there a sample code?
best regards,
|
|
|
|
|