|
Do you mean you don't see the file ? You've changed the path you build to.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
You may check the path!
学阿
|
|
|
|
|
Yes,
I can't see the file....but you know what, I am trying to execute a dll file, and we can't execute a DLL file....
Thanks
Preeti9
|
|
|
|
|
Hi Preeti9,
What do you mean? I couldn't understand.. You CANNOT execute a dll file?. I need more info pls..
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
Good afternoon, all
Has anyone seem this before?
error LNK2001: unresolved external symbol _WNetConnectionDialog@8
would it be some kind of the link that I am missing on the setting? or missing certain include file?
thanks!
|
|
|
|
|
I'm guessing that you've added a call to WNetConnectionDialog recently. The actual implementation of different parts of the Windows API are in different .dll files, and if you call one of the less used functions, you may have to instruct the linker to include the corresponding .lib file. In this case, you'll need to make sure you link with mpr.lib .
|
|
|
|
|
|
ur r missing Mpr.lib u can refer to msdn also
|
|
|
|
|
thanks and have a good weekend!
|
|
|
|
|
I have device driver and I want to write in a file from within the driver.
I am using ZwCreateFile()
ZwWriteFile()
ZwClose() functions.
When I call the InitializeObjectAttributesfunction()
i do not know how should the object name look like.
I mean if my file name is: D:\\status.txt or something like this:
\Device\HarddiskVolume1\status.txt
I want to ask now if these are the functions I should use when writting in a file from the kernel:
Here is a piece of code.
Can someone tell me what I do wrong?
<br />
<br />
NTSTATUS WriteStatusInFile(<br />
IN PCWSTR FileName,<br />
IN HANDLE hProcessId<br />
)<br />
{<br />
UNICODE_STRING ObjN;<br />
OBJECT_ATTRIBUTES ObjAttrib;<br />
UNICODE_STRING ObjName;<br />
IN HANDLE hFile;<br />
IN IO_STATUS_BLOCK StatBlock,WStatBlock;<br />
RtlInitUnicodeString(&ObjN,L"\\D:\\status.txt");<br />
InitializeObjectAttributes(&ObjAttrib,&ObjN, OBJ_KERNEL_HANDLE , NULL, NULL);<br />
<br />
<br />
ZwCreateFile(&hFile,<br />
FILE_WRITE_DATA|FILE_APPEND_DATA,<br />
&ObjAttrib,<br />
&StatBlock,<br />
0,<br />
FILE_ATTRIBUTE_NORMAL,<br />
FILE_SHARE_WRITE,<br />
FILE_CREATE |FILE_OPEN,<br />
FILE_SEQUENTIAL_ONLY,<br />
NULL,<br />
0<br />
);<br />
ZwWriteFile(<br />
hFile,<br />
NULL,<br />
NULL,<br />
NULL,<br />
&WStatBlock,<br />
L"Process Created or Terminated\n",<br />
sizeof("Process Created or Terminated\n"),<br />
NULL,<br />
NULL<br />
);<br />
<br />
ZwClose(hFile);<br />
<br />
return WStatBlock.Status;<br />
<br />
}<br />
Thanks in advance.
gabby
|
|
|
|
|
I don't understand why compiler(Microsoft Visual C++ 7.1) always makes code that cleans stack from parameters after execution function that declared as __stdcall:
void corrupt {
typedef HANDLE (__stdcall *FOO)(...); // function must be called via std convention
FOO foo = (FOO)GetProcAddress(LoadLibrary("kernel32.dll"), "GetModuleHandleA");
(*foo)(NULL);
}
Disassembly:
push offset foo.??_C@_0BB@HNEJOH> ; /ProcNameOrdinal = "GetModuleHandleA"
push offset foo.??_C@_0N@MDJJJHM> ; |/FileName = "kernel32.dll"
call near dword ptr ds:[<&KERNEL32.LoadLibraryA> ; |\LoadLibraryA
push eax ; |hModule = 0012F34C
mov edi, dword ptr ds:[<&KERNEL32.GetProcAddress> ; |kernel32.GetProcAddress
call near edi ; \GetProcAddress
push 0
call near eax ; GetModuleHandleA call
add esp, 4 ; An unwanted stack clean
After execution this function we'll see an access violation, because the return address will be wrong.
How can I fix that problem?
PS In project options __stdcall is default calling convention
|
|
|
|
|
you can mark individual functions as "cdecl". then, the calling code is responsible from cleaning the stack.
int __cdecl foo(int a);
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
They are always situated in system dll's
|
|
|
|
|
Hi
There is a flaw in your code. Thats why it is crashing. Basically compilier try to do second stack clean up..
typedef HANDLE (__stdcall *FOO)(...); // function must be called via std convention
The above declaration is the problem.. As is GetModuleHandleA is a standard function following pascal calling (Standard windows) convention.
In Pascal calling convention, the number of paramter we are passing to the function and the number of bytes required for that must be known before calling a function. By that way the called function will do clean up.
You have declared a function pointer like this..
typedef HANDLE (__stdcall *FOO)(...);
(...) which means the function would accept many number of parameters. C/CPP compiler would consider this this is a "C" calling convention. You are calling function in the dll.. That is following pascal calling convention..
When you call the function, the called function will unwind the stack as of pascal calling convention. And your calling function will also try to empty the non-existing stack(Already cleaned).. Thus a problem..
See my uncorrupt() function against your function.
void nocorrupt()
{
typedef HANDLE (__stdcall *FOO)(LPCTSTR); // function must be called via std convention
FOO foo = (FOO)GetProcAddress(LoadLibrary("kernel32.dll"), "GetModuleHandleA");
(*foo)(NULL);
}
This won't crash..
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
>There is a flaw in your code. Thats why it is crashing. Basically compilier try to do second stack clean up.. .
I know that compiler do stack cleaning after calling this function and in my disassembly I marked this place with comment.
>>typedef HANDLE (__stdcall *FOO)(...); // function must be called via std convention
>The above declaration is the problem.. As is GetModuleHandleA is a standard function following pascal calling (Standard windows) convention.
This is not true. Pascal convention isn't standart windows dll's convention! Standart Windows convention is exacly STD.
If you don't trust me just try this code:
#include <stdio.h>
#include <windows.h>
void main()
{
const char* src = "Let's test";
USHORT srcSz = strlen(src);
char *dst = new char[srcSz+1];
memset(dst, 0x00, sizeof(src)+1);
void *lpLstrcpy = GetProcAddress(LoadLibrary("kernel32.dll"), "lstrcpy");
printf("Testing STD Calling Convention...\n"
"In this convention parameters must be stored in stack in back order\n"
"And function must clean all it's parameters from stack by itself\n");
__asm {
; I put in stack all parameters in flip order(STD convention rule)
push src ; lstrcpy(DESTINATION, SOURCE);
push dst ; ^ |
call lpLstrcpy ; ----------+
}
printf("In dst variable now : %s\n", dst);
memset(dst, 0x00, srcSz+1); // Zero memory at dst
printf("\nTesting Pascal Calling Convention...\n"
"In this convention parameters must be put in stack in normal order\n"
"And function doesn't cleans all it's parameters from stack by itself\n");
__try {
__asm {
push dst
push src
call lpLstrcpy
; Clean stack
sub esp, 0x08
}
} __except (EXCEPTION_EXECUTE_HANDLER) {
printf("\nOops!\n\n");
}
printf("In dst variable now - %s\nOf course you don't see anything after '-'\n", dst);
system("PAUSE");
}
>In Pascal calling convention, the number of paramter we are passing to the function and the number of bytes required for that must be known before calling a function.
>By that way the called function will do clean up.
If function want it can clean stack if don't can not.
Conventions is a way to describe how compiler must generate it's code to call some function.
>You have declared a function pointer like this..
>typedef HANDLE (__stdcall *FOO)(...);
>(...) which means the function would accept many number of parameters. C/CPP compiler would consider this this is a "C" calling convention. You are calling function in the dll.. That is following pascal calling convention..
I know that (...) means that to function will be passed unknown number of parameters.
By UNIX way (...) must be replaced with 'va_list'.
>When you call the function, the called function will unwind the stack as of pascal calling convention. And your calling function will also try to empty the non-existing stack(Already cleaned).. Thus a problem..
>See my uncorrupt() function against your function.
>void nocorrupt()
>{
>typedef HANDLE (__stdcall *FOO)(LPCTSTR); // function must be called via std convention
>FOO foo = (FOO)GetProcAddress(LoadLibrary("kernel32.dll"), "GetModuleHandleA");
>(*foo)(NULL);
>}
>This won't crash..
I don't know how many parameters will be passed to function, but in your code we have a fixed number of parameters - 1.
|
|
|
|
|
Anton Mikhalyov,
Your Code is successfully crashing . Fine. But I couldn't understand what you are trying to convey..
Can you list out the difference between Standard Windows calling convention and PAscal calling convention?
When I look into windef.h PASCAL defined as __stdcall..
What I need is
1. How arguments are passed?
2. How they are arranged in stack?
3. Who will do cleanup?
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
I know how to start Word and open 2 word documents - one existing and one new. I want to copy specific pages from the existing word document and paste them one at a time into the new document. So far I haven't even managed to copy any text of any description, my paste is just pasting whatever happened to be on the clipboard before.
|
|
|
|
|
sammiantha wrote:
I know how to start Word and open 2 word documents...
Briefly, how are you doing this?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Probably ShellExecute ...!?!?
gabby
|
|
|
|
|
Are you doing this in VB/VBA/c++/??
If I were doing it in c++, I'd embed the type library in my program, use the Word Automation objects to create an instance of Word, open a document, then use (sketchy becuase I dont have the details right in front of me) a select/range object to define a range of pages/paragraphs/lines within the document (which may be all), then execute the copy method .. then create a new document, select the 1st line, and execute the paste method ..
it may be the selecting text thats causing you grief - you havnt said you're defining what to copy/how you're marking the text
if you post some code I can take a look over the weekend if I get time (Its Friday afternoon here)
'G'
|
|
|
|
|
Garth J Lancaster wrote:
If I were doing it in c++, I'd embed the type library in my program, use the Word Automation objects to create an instance of Word, open a document, then use (sketchy becuase I dont have the details right in front of me) a select/range object to define a range of pages/paragraphs/lines within the document (which may be all), then execute the copy method .. then create a new document, select the 1st line, and execute the paste method ..
I'm using c++.
Okay, remember that I'm new to this automation - and my code may be awful for someone who actually knows what they are doing.
G, I am with you, up until 'use a select/range object to define a range...' which is where my trouble begins.
Basically I used this KB article to get started:
http://www.kbalertz.com/Feedback.aspx?kbNumber=178749[^]
(obviously using Word not Excel).
Then I have the following:
COleVariant vtOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR),<br />
vtTrue((short)TRUE),<br />
vtFalse((short)FALSE);<br />
<br />
<br />
_Application app; <br />
Documents oDocs;<br />
_Document oDoc;<br />
_Document newDoc;<br />
Paragraphs oParagraphs;<br />
Selection oSelection;<br />
COleVariant fileName;<br />
fileName = "C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\ReadingRecs\\file.doc";<br />
<br />
if(!app.CreateDispatch("Word.Application"))<br />
{<br />
AfxMessageBox("Couldn't start Word.");<br />
}<br />
else<br />
{ AfxMessageBox("Word opened.");<br />
app.SetVisible(TRUE);<br />
<br />
oDocs = app.GetDocuments();<br />
oDoc = oDocs.Open(fileName,vtOptional, vtOptional,vtOptional, vtOptional, vtOptional,vtOptional, vtOptional, vtOptional,vtOptional, vtOptional, vtOptional);<br />
<br />
fileName = "c:\\files\\temp.doc";<br />
newDoc = oDocs.Add(fileName,vtOptional, vtOptional, vtOptional);<br />
<br />
}
I attempted to use another vaguely relevant KB article: http://www.kbalertz.com/kb_220911.aspx[^] which is where I found the document opening/creating stuff.
Any help anyone could give me would be great.
-Samantha
|
|
|
|
|
Problem solved.
Solution: Stop wondering aimlessly around the classes that word has to offer - create a macro to do the selection and run that macro using Application.Run() from c++ program.
|
|
|
|
|
|
I'd been told by many to make a macro and convert the VB code to c++; that it was easy. That didn't work out for me. Then someone mentioned the Application.Run() function and after figuring out how to use that, I'll be using macros wherever possible from now on! The only problem I can see with that though, is that I won't be able to use the program on just any computer. It won't work unless the right macro is in normal.dot. So my next job will be looking for an easy way to install my macro when the program runs for the first time.
There will also be a problem when I try to use the program on a different version of word - because automation makes you use a different header file depending on the version.
Why I create these projects for myself I don't know...
|
|
|
|
|
Hey - its a challenge, that 1) you didnt give up on and 2) you're willing to keep trying at - so dont knock yourself, and give yourself some credit - you didnt find the answer the first time but you got it a different way, maybe sometime later you'll be browsing some code and it'll click - your tenacity puts you ahead of lots of people who would have chucked it in the 'too hard' basket
Do when/if you get time download the samples etc and have a look through them - you might just spot the missing link ..
'G'
|
|
|
|
|