|
john john mackey wrote:
What I want to do is get/set the Section names within a .INI file.
Use GetPrivateProfileString(NULL, ...) .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Sorry, but this is the closest match forum I could find on CP:
I have a native C dll that exports one function besides DllEntryPoint, FuncX. I'm trying to find out how FuncX communicates with it's caller, because it has a void return type and no parameters. When I call it from a C# harness, I get an AccessViolationException - Attempted to read or write protected memory.
I have a hunch that its client application may allocate a buffer for sending or receiving values from the dll. Is this a valid hunch?
I can't debug the client application because for some reason it doesn't run, so I can't start it and attach to the process. I can, however, disassemble it in IDA Pro, but don't know how to, if I can, try and debug it in there.
|
|
|
|
|
Can you debug it from a C or C++ client, so you can step into the function in (native) disassembly mode?
Brady Kelly wrote: I'm trying to find out how FuncX communicates with it's caller, because it has a void return type and no parameters
So there's no visible interface? That says global data to me - which requires a commonly defined symbol.
Brady Kelly wrote: I have a hunch that its client application may allocate a buffer for sending or receiving values from the dll. Is this a valid hunch?
Sounds possible - but how does the buffer get into FuncX?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote:
Can you debug it from a C or C++ client, so you can step into the function in (native) disassembly mode?
I'd have to write that client, after a ten minute C refresher, but it's possible, and I'm not scared.Stuart Dootson wrote: Sounds possible - but how does the buffer get into FuncX?
I suspect it's at something like a constant, known offset or address in the calling code, if that's at all possible.
Right now I'm busy with an IDA Pro tutorial, to get started exploring the internals with some muscle and some baby help behind me.
|
|
|
|
|
Brady Kelly wrote: I suspect it's at something like a constant, known offset or address in the calling code, if that's at all possible
That sounds scary Especially as DLLs can be relocated...
Brady Kelly wrote: I'd have to write that client, after a ten minute C refresher, but it's possible, and I'm not scared.
extern __declspec(dllexport) void FuncX();
#pragma comment(lib, "whatever-the-DLLs-lib-file-is");
int main(int argc, char** argv)
{
FuncX();
}
or if you don't have a lib file:
#include <Windows.h>
typedef void (*FuncXType)();
int main(int argc, char** argv)
{
HMODULE myDll = ::LoadLibrary(DLL-name);
FuncXType pFuncX = (FuncXType)GetProcAddress(myDll, "FuncX");
pFuncX();
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks soo much! I'll try it as soon as I get home.
|
|
|
|
|
How to parse a CString: 1,1,E1,0.13060,-0.40193,-0.90631
which is a line delimited with commas of a mixture of numvers and characters.
I can read in: 1,1,E1,0.13060,-0.40193,-0.90631
using:
fscanf( f_ptr1,"%s\n",headline.GetBuffer(MAX_PATH));
headline.ReleaseBuffer();
Thanks
|
|
|
|
|
Something like:
CString headline;
...
CString Token;
int Pos = 0;
while (!(Token = headline.Tokenize(_T(","), Pos)).IsEmpty())
{
}
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
After trying yours, I got:
'Tokenize' : is not a member of 'CString'
Please check and help
|
|
|
|
|
Works for me, maybe it is some version difference or so...hmmm...that CString is the MFC CString, not some custom class, right?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Yes, CString is a MFC CString. I am using C++ 6.
|
|
|
|
|
7 here, i guess Tokenize didn't exist in version 6 yet. Well, you can either try using this[^], or hope someone who knows version 6 comes along and helps you.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Thanks. I think I need to port my program to a newer version.
Is it be much trouble to use a newer version of compiler for the present program ?
Any comments
Thanks.
|
|
|
|
|
mrby123 wrote: How to parse a CString: 1,1,E1,0.13060,-0.40193,-0.90631
which is a line delimited with commas of a mixture of numvers and characters.
By using AfxExtractSubString() .
Also, since you are using MFC, you can forgo the use of FILE and fscanf() and use CStdioFile instead. Calling GetBuffer() like you are is unnecessary and potentially dangerous.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Why not just copy it to a char * and use strtok
a programmer traped in a thugs body
|
|
|
|
|
You might want to suggest that to the original poster, rather than David.
(I suspect he knows strtok)
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Hello guys,
i need you help with a C program that reads names from a .txt file and sort them in alphabetical order.
I have written the code for the reading part and it seems to work, but I don't know how to orgnize the bubble sort algorithm in order to compare strings and swap them.
Could you please give me some hints?
Thanks a lot,
raeiko
Here is my code:
#define SIZE 30
int main()
{
char name[ SIZE ];
FILE *fpPtr;
if ( ( fpPtr = fopen( "sorted_file.txt", "r" ) ) == NULL ) {
printf( "File could not be opened\n" );
}
else {
printf( "%s\n", "Name" );
fscanf( fpPtr, "%s", name );
while( !feof( fpPtr ) ) {
printf( "%s\n", name );
fscanf( fpPtr, "%s", name );
}
fclose( fpPtr );
}
return 0;
}
|
|
|
|
|
Why write your own bubble sort when the standard library has a quicksort built in. That way, you get a fast sort routine that you know works...
99.9999% of the time, it's better to use someone else's library code rather than write your own.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: Why write your own bubble sort when the standard library has a quicksort built in.
Perhaps it's an academic exercise.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
That's what I figured - in which case, helping him isn't helping him
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
raeiko wrote: ...but I don't know how to orgnize the bubble sort algorithm in order to compare strings and swap them.
You first need to get a working bubble-sort algorithm before moving on.
int nNumbers[] = { 1, 7, 4, 10, 3, 5, 6, 9 };
int nCount = sizeof(nNumbers) / sizeof(nNumbers[0]);
...
BubbleSort(nNumbers, nCount); Work on this, and when you get stuck, we'll be glad to help.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I think tree structer is far more better than the bubble sort in actual work, if you are doing a actual work not homework. there is less moving when the tree is used.
|
|
|
|
|
Hello,
I'm writing this program for an academical assignment that is why i need to use the bubble sort algorithm, even though, from what i undersand, is not the most suitable solution.
I have tried to go on with my code but it's still not working and i'm getting more and more confused because i don't have really clear in my mind how to handle pointers...
Here is what i have done but i'm sure it's completely wrong
#include <stdio.h>
#include <string.h>
#define SIZE 30
int main()
{
char name[ SIZE ];
FILE *fpPtr;
if ( ( fpPtr = fopen( "sorted_file.txt", "r" ) ) == NULL ) {
printf( "File could not be opened\n" );
}
else {
printf( "%s\n", "Name" );
fscanf( fpPtr, "%s", name );
while( !feof( fpPtr ) ) {
printf( "%s\n", name );
fscanf( fpPtr, "%s", name );
}
fclose( fpPtr );
}
for ( pass = 1; pass < SIZE; pass++ ){
for ( counter = 0; counter < SIZE - 1; counter ++ ){
if ( *name [ counter ] > *name [ counter + 1 ] ) {
hold = *name[ counter ];
*name[ counter ] = *name[ counter + 1 ];
*name[ counter + 1 ] = hold;
}
}
}
return 0;
}
|
|
|
|
|
Please help:
Here is code I tried, but not working.
*/
char string[150];
char * dummy;
fscanf(f_ptr1,"%s\n",string); reading a line: 1,1,E1,0.13060,-0.40193,-0.90631
nl = int(strtok(string, seps)); // Get the first token
nd = int(strtok(string, seps)); // Get the second token
dummy = strtok(string, seps); // Get the third token
xx = atof(strtok(string, seps)); // Get the fouth token
yy = atof(strtok(string, seps)); // Get the fifth token
zz = atof(strtok(string, seps)); // Get the sixth token
Here nl, nd are integer, xx,yy,zz, are float.
Please point out how to make codes work. Thanks a lots
|
|
|
|
|
Two mistakes:
- You can't get an integer from a string by casting - use atol (that's like atof for integers)
- You only pass the string pointer the first time you call strtok for a string. The other times, pass a null pointer
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|