|
My first suggestion is for you to "play" or "Experiment" with pointers until you understand what you can and should not do.
Phil
|
|
|
|
|
Coming from assembly before C/C++ myself - pointers are the closest to a one-to-one relationship
with CPU addressing. It's the lowest level abstraction, just above "Indexed Addressing Mode" in
assembly. The benefit is performance and control. The drawback is when mistakes are made coding,
they are bad - the compiler can't save you Higher level languages hide these issues,
sacrificing a bit of performance for safety and ease of use (or hiding the concept of memory
addressing altogether).
My 2 cents.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Yes, power corrupts. When you mess up, it corrupts absolutely.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Confirmed!
Robert Nicholas
---------------
If you see only one solution, then you don't understand the problem.
|
|
|
|
|
You have received some good answers so I will keep this simple.
A pointer is the address to a block of memory, just as a street address is the address of the house and not the house itself. If you wish to have a separate function manipulate the contents of the memory block, then you need to pass the address to that function so that it knows where the memory block is located.
The C string manipulation functions are good examples of using pointers: see strcpy amongst others.
If you want to create your own liked list, instead of using the STL ‘list’ template, then pointers are essential: struct node { some data variables; struct node* pNextNode; };
Example (in generic C):
void clear_buffer(void* pBuffer, unsigned nSizeInBytes)
{
unsigned char* p = (unsigned char*)pBuffer;
unsigned i;
for( i = 0; i < nSizeInBytes; ++i )
p[i] = 0;
}
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Hi,
I use the function ShellExecute to start an application, say MyApp.exe. Does anyone know how to terminate the process of MyApp?
It seems ShellExecute can return a handle (the first parameter of ShellExecute). I tried to use TerminateProcess to end MyApp but I failed. It seems the handle is not the "real handle" of the process, right?
Thank you a lot for your help!
Jeffrey
|
|
|
|
|
I've never tried to terminate something spawned from ShellExecute so I can't help there but...
A quick search of my projects, I found one that uses CreateProcessWithLogonW and later if problems develop it resorts to using TerminateThread utilizing the handle in the processInformation structure that is filled in CreateProcessWithLogonW. CreateProcess has a similar parameter list and utilizes the processInformation as well so I would guess you should be able to use CreateProcess for the same purpose though I've never tried it.
Hope that helps.
|
|
|
|
|
You'll need to use ShellExecuteEx() to get a handle on the new process.
|
|
|
|
|
Thank you, Bob and Mike.
When I get the handle on the new process, do I call TerminateProcess to close it? Thank you, Mike.
Jeffrey
|
|
|
|
|
sunshine jeffrey wrote: When I get the handle on the new process, do I call TerminateProcess to close it?
Yep
|
|
|
|
|
Although sometimes the only way, in general I question the wisdom of using TerminateProcess to stop a process. Doing so could result in corruption of data files for example. It would be better to try to close down the process gracefully first and only terminate as a last resort. The WM_CLOSE message and the GenerateConsoleCtrlEvent function are of interest in this respect.
Steve
|
|
|
|
|
I agree with Stephen. When using TerminateProcess, you have no idea what the process is doing at
that instant or what state it's in. If at all possible, there sould be some kind of interprocess
communication used to let the spawned process close itself gracefully.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thank you for your suggestions, Stephen and Mark. I also kinda feel TerminateProcess a little brutal I will try the ways as suggested. Thanks
Jeffrey
|
|
|
|
|
What is message loop in MFC
|
|
|
|
|
|
|
hello,
I have a crystal report (version 8.5) which has about 10 on-demand sub-reports embedded in it. But when the report opens, the hyperlinks for them do not work, as in, they appear as plain-text, not clikable.
The same report works just fine when viewed in crystal software. I am using visual c++ 6.0. Is there any addtional coding to be done to enable it.?
Also, how do I determine which subreport the user has clicked on, in order to open the appropriate sub-report. Right now, all i am able to do is to scroll through each of these subreports. But i dont know how to stop and display the one that the user has clicked on.
Kindly help
|
|
|
|
|
I would like to know whether a file(*.txt) is normal ansi text file or unicode file by program. Is there standard class in C++/MFC for reading UNICODE file?
Best Regards,
Suman
|
|
|
|
|
As with anything else, it is not a straight forward process:
http://codesnipers.com/?q=node/68[^]
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
If the app expects the files to be relatively small, you can read in the file raw into a buffer and use IsTextUnicode() against the buffer using the IS_TEXT_UNICODE_SIGNATURE flag.
In an MFC app, this should occur in the serialize method or be a function called from the serialize method. to get the filesize, get the file pointer using ar.GetFile() and call GetLenth() on the file pointer. Obviously, you'll read in the raw data using ar.Read().
Not the most efficient way I'll bet, but it seems to work. However, note the disclaimer in MSDN in the remarks section for IsTextUnicode()
|
|
|
|
|
AFAIK, there is a two byte signature at the very start of a UNICODE text file.
The signature consists of the character values FF hex (255 decimal) and FE hex (254 decimal).
They can be in the order FEFF or FFFE, which flags if the bytes in the file is big or little endian. I don't remember which is which, but Google is your friend.
You can try it yourself, just create a text file with Notepad, save it in UNICODE and then dump the file with a hexdump (or hexeditor) program.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
hi,
I'm writing a ActiveX(OCX file) project in VC6 ,I want create one method in my project, this method have 2 parameters change in this method ,then when call this method in any language ( example delphi) I want see value change in these parameters ,
In fact I want my method return 2 strings value .
I don't know type these parameters and ...
thanks for any answer.
|
|
|
|
|
Accept these two parameters by reference / pointer (out parameter).
[id(1), helpstring("XXXX")] HRESULT foo([out,retval] long* out1, [out,retval] long* out2);
Regards,
Paresh.
|
|
|
|
|
thanks for your help paresh,
but, my project is AcriveX in Visual C++ 6 , and I create my method by classwizard, in classwizard type parameters is limited by combobox and have not this type ("[out,retval] long* out1") but I write this type manual and build my project , VC6 give error syntax error : '['
regards
|
|
|
|
|
Hello,
I am attempting to create a C++ dll for use with Visual Basic. I have managed to get my dll working when I late bind in Visual Basic6 using Private Declare Function ... but I wanted to make the dll so it was referencable in VB6, and have the function appear in the intellisense - without having to declare the dll and its functions in my VB6 project. I have been using this (dated) tutorial from microsoft as reference
I have achieved this with a fairly simple dll that takes a long from VB and returns a long. Here is the C++ code
<br />
int __stdcall testfunc(int incoming)<br />
{<br />
incoming += 10;<br />
return incoming;<br />
}<br />
and the code in the .idl file
<br />
[<br />
uuid(B99D1487-BC95-4d28-A064-55A4ED191343),<br />
helpstring("vbtestdll"),<br />
lcid(0x0409),<br />
version(1.0)<br />
]<br />
library vbtestdll<br />
{<br />
[<br />
helpstring("Sample functions exported by vbtest.dll"),<br />
version(1.0),<br />
dllname("vbtestdll.dll")<br />
]<br />
module MyDllFunctions<br />
{<br />
<br />
[<br />
<br />
helpstring("Returns an integer."),<br />
entry("testfunc")<br />
]<br />
int __stdcall testfunc([in] int incoming);<br />
}<br />
}<br />
This is how it appears in the VB6 Object Browser. the type library references perfectly and I can use the function in vb, just like it was a native function.
My problem arrises when I try a more complicated function. The function I am trying to make available to VB6 returns char* - Now this seems to work perfectly when I late-bind the function using
Private Declare Function encrypt_string Lib "BlowDll.dll" (ByVal key As String, ByVal str As String, ByVal MircRet As Boolean) As String
I pass it 2 strings and either true or false, and it returns an encrypted string perfectly.
However, when I try to add this function to a .idl file, and reference the type library in visual basic, the object browser reports that the return type is "As unsupported variant type". It does however recognise that strings must be passed to the function (which are char* in cpp)
Here is a screenshot of the object browser in VB6
I have pretty much narrowed the problem down to how the function is declared in the .idl file, here is the declaration in the .idl file, the rest is identical to the above example, apart from the .dll name and name for the libraray and the uuid.
char* __stdcall encrypt_string([in, string]char *pinkey,[in, string]char *pinstr,[in]int mIRCret);
I have tried a few variations of this.. but none of them seem to make any difference..
<br />
<br />
[out, string] char* __stdcall encrypt_string([in, string]char *pinkey,[in, string]char *pinstr,[in]int mIRCret);<br />
<br />
[string] char* __stdcall encrypt_string([in ,string]char *pinkey,[in, string]char *pinstr,[in]int mIRCret);<br />
<br />
I am almost positive it has to do with the having [string] infront of char * as when I remove this from the arguments they also come up as unsupported variant type.
does anyone any any suggestions on how to resolve this issue..
thanks in advance for any help!
|
|
|
|
|