|
If it's crashing at the point you mentioned, it's because it is unable to successfully process the parameters. Check David Crow's comments, I think he is probably right. Also, I am not sure, but check your syntax. I am not sure if I remember correctly, but when I learned C++, I was taught that you typically pass in an array as one parameter, and the subscripts as additional parameters - or something like that, I am not sure.
Anyway, you may want to use vectors instead.
I hope this helps.
Peace,
BP
|
|
|
|
|
KaKa' wrote: nt rank(int num,int data[Tuples][Features],
double dist[Tuples],double rank[Tuples])
change it to
int rank(int num,const int **data,const double *dist,const double * rank,int Tuples,int feature)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
How do you use this function?
|
|
|
|
|
Hi,thanks all for the replies. I think it could be a stack overflow because previously the 2D array was 128 rows by 46 columns but when I expanded it to 1600 rows, the program crashed.
So, if the the function parameters are replaced by pointers instead of arrays, will the crash problem be solved?
I call the rank function using this: rank(n,d,distance,r);
where n is the integer variable, d is the 2D array while distance and r are the 1D arrays.
|
|
|
|
|
Hi,
I have a small bit of C++ program, but I am not programmer in C++. Could anyone help me to explain or rewrite similar program in VB6??
This code is looking for this line in file:
DPB="FEFC52D7AE2930463046CFBA3146BBA8AF10AED2E858FFF2E7E9730F1BDB426A4174B6D67A4E86"
And then it is processing it. This line contains password (in this case is '000000000'), I think this line is a bit changed so it is incorrectly giving and answer. That's why I need to understand this C++ code to make a correction to a code and get correct password.
C++ program looks like this:
<br />
#include <stdio.h><br />
#include <windows.h><br />
#include <conio.h><br />
#pragma hdrstop<br />
#include <condefs.h><br />
<br />
#define BLOCK_SIZE 32768<br />
<br />
<br />
int memstr(const char *buf, const char *s, size_t size)<br />
{<br />
int off;<br />
const char *s_temp;<br />
<br />
if(!buf || !s || !(*s)) return -1;<br />
<br />
for(off = 0; off < size; off++)<br />
{<br />
for(s_temp = s; *s_temp != 0 && *buf == *s_temp; buf++, s_temp++)<br />
{<br />
off++;<br />
if(off >= size) return -1;<br />
}<br />
if((*(buf - 1) == *(s_temp - 1)) && *s_temp == 0) return off;<br />
buf++;<br />
}<br />
return -1;<br />
}<br />
<br />
LPSTR findEncryptPass(const char *filename)<br />
{<br />
FILE *prot_file;<br />
char *buff = 0, *s;<br />
size_t rc;<br />
int off;<br />
<br />
prot_file = fopen(filename, "rb");<br />
if(!prot_file) return 0;<br />
buff = (char *)malloc(BLOCK_SIZE);<br />
if(!buff) return 0;<br />
do<br />
{<br />
rc = fread(buff, 1, BLOCK_SIZE, prot_file);<br />
if(!rc) break;<br />
off = memstr(buff, "DPB=\"", BLOCK_SIZE);<br />
if(off < 0)<br />
{<br />
if(rc < BLOCK_SIZE) break;<br />
fseek(prot_file, -32, SEEK_CUR);<br />
continue;<br />
}<br />
fseek(prot_file, off - rc, SEEK_CUR);<br />
rc = fread(buff, 1, BLOCK_SIZE, prot_file);<br />
if(!rc) break;<br />
s = strchr(buff, '\"');<br />
*s = 0;<br />
return buff;<br />
} while(!feof(prot_file));<br />
free(buff);<br />
return 0;<br />
}<br />
<br />
void decryptPassword(const char *encrypt_pass, char *s)<br />
{<br />
char str[128], ch;<br />
char hs[] = { 0, 0, 0 };<br />
int v1, v2, i, l;<br />
int begin_found = 0;<br />
<br />
*s = 0;<br />
<br />
for(i = 0; encrypt_pass[i*2]; i++)<br />
{<br />
hs[0] = encrypt_pass[i*2]; hs[1] = encrypt_pass[i*2+1];<br />
v1 = strtol(hs, 0, 16);<br />
hs[0] = encrypt_pass[i*2+4]; hs[1] = encrypt_pass[i*2+5];<br />
v2 = strtol(hs, 0, 16);<br />
if(!begin_found)<br />
{<br />
if(v1 == v2) begin_found = 1;<br />
}<br />
else<br />
{<br />
if(v1 != v2)<br />
begin_found = 0;<br />
else<br />
{<br />
i += 3;<br />
break;<br />
}<br />
}<br />
}<br />
<br />
if(!begin_found) return;<br />
<br />
for(ch = 0, l = 0; encrypt_pass[i*2+2]; i++, l++)<br />
{<br />
hs[0] = encrypt_pass[(i-2)*2]; hs[1] = encrypt_pass[(i-2)*2+1];<br />
v1 = strtol(hs, 0, 16);<br />
hs[0] = encrypt_pass[i*2]; hs[1] = encrypt_pass[i*2+1];<br />
v2 = strtol(hs, 0, 16);<br />
ch = (ch + (char)v1) ^ (char)v2;<br />
str[l] = ch;<br />
}<br />
str[l] = 0;<br />
CharToOem(str, s);<br />
}<br />
<br />
#pragma argsused<br />
int main(int argc, char **argv)<br />
{<br />
char s[128];<br />
char *encrypt_pass_str;<br />
<br />
if(argc < 2)<br />
{<br />
printf("Usage: vbakey.exe filename\n");<br />
return 1;<br />
}<br />
<br />
if(!(encrypt_pass_str = findEncryptPass(argv[1])))<br />
{<br />
printf("Password not found\n");<br />
return 1;<br />
}<br />
<br />
decryptPassword(encrypt_pass_str, s);<br />
printf("File password: %s\n", s);<br />
free(encrypt_pass_str);<br />
printf("Press any key for continue ... \n");<br />
getch();<br />
return 0;<br />
}<br />
This is whole program. And I don't need any conversion or explanation on how to get arguments for file neither about function 'findEncryptPass' which I assume will return in this case "FEFC52D7AE2930463046CFBA3146BBA8AF10AED2E858FFF2E7E9730F1BDB426A4174B6D67A4E86". I am most interested in function 'decryptPassword'. How it works and what it returns.
Thanks for any help.
|
|
|
|
|
Tomazas77 wrote: That's why I need to understand this C++ code...
Using the debugger will go a long way towards this.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I don't have C++ debugger. That's way I am asking for help.
|
|
|
|
|
If you have VC++, then you have a debugger.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi,
In my application I need to post a string using postmessage() function. Here my string is of type LPCSTR without null-termination. I post this string using WPARAM parameter of postmessage() function, but on the receiver side I get nothing. Can I know how can I post this string using postmessage() function?
Thanks,
Priyank
|
|
|
|
|
priyank_ldce wrote: I post this string using WPARAM parameter of postmessage() function...
What does this look like?
priyank_ldce wrote: ...but on the receiver side I get nothing.
How are you handling the message?
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Since you posted no code, I'm guessing here ...
But it sounds like you are using a CString object and passing it to PostMessage:
{
CString strMyData = "Junk";
PostMessage(SomeHwnd, SomeMsg, (LPARAM)(LPCTSTR)strMyData, 0);
}
This won't work since when the CString goes out of scope, it is cleaned up. Thus, when your window gets the message, the pointer to the memory is no longer valid for that string.
Is there some reason you are using PostMessage instead of SendMessage? If you are able to switch (generally, PostMessage is used in applications that need to be redesigned/refactored), the code will work, so long as you make a copy of the LPCTSTR in the handler receiving the message.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
priyank_ldce wrote: Here my string is of type LPCSTR without null-termination.
How do you know its length then?
|
|
|
|
|
you can try AddAtom()
just a suggession, because I have used it in a my project where I was failing in my all trys, about passing a string at just my application window creation time.
Tanvon
the brain behind ...
I Blog here
|
|
|
|
|
Tanvon wrote: AddAtom
it has text limit of 255 only... i don't believe this will help + as the guy want that string is not null terminated!.. so AddAtom Api(not function ) will work in his case!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
if u are sending the string to a window in another process, this should not work since independent processes have independent memory spaces - no shared memory segments..
if u r sending it to the same process, make sure it doesnt go out of scope.
Mohamad
And ever has it been that love knows not its own depth until the hour of separation
|
|
|
|
|
If you like a simple IPC via messaging, use WM_COPYDATA message. You could send data with this message to another window. This article shows how.
Best,
Jun
|
|
|
|
|
Jun Du wrote: If you like a simple IPC via messaging, use WM_COPYDATA message. You could send data with this message to another window. This article shows how.
good example.. but you can still send it by GlobalAlloc!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Absolutely. I thought he was looking for some simple data exchange via messages.
Best,
Jun
|
|
|
|
|
Thanks for your reply.
Now I am using WM_COPYDATA to send string to my other application. I also want to send 2 integer values with this string. So, I made a structure of 1 string and 2 integers. But on the other side I am able to get 2 integer values but not string. I get blank string on that side. Here I am sending my code.
Sender application
struct MYDATASTRUCT
{
LPCSTR myString;
int myX;
int myY;
};
MYDATASTRUCT myStringData;
myStringData.myX = X;
myStringData.myY = Y;
myStringData.myString = lpString;
COPYDATASTRUCT myData;
myData.dwData = 0;
myData.cbData = sizeof(myStringData);
myData.lpData = &myStringData;
::SendMessage(g_mainHwnd,WM_COPYDATA,NULL,(LPARAM)&myData);
Receiver application
PCOPYDATASTRUCT myData = (PCOPYDATASTRUCT)lParam;
MYDATASTRUCT* myStringData = (MYDATASTRUCT*)myData->lpData;
int X = myStringData->myX;
int Y = myStringData->myY;
LPCSTR lpString = myStringData->myString;
Now when I am sending this string directly without structure and integer value I am able to get that string on receiver application.
Can anyone find what is the problem with structure code?
Thanks,
Priyank
|
|
|
|
|
Actually I made an API Hook DLL to hook any application for ExtTextOut() winapi. Now when my DLL get this api call I need to process string in my other application. But I am not able to send or post this string to my application. Any suggestion how can I get this string in my application?
Thanks,
Priyank
|
|
|
|
|
I have seen in a couple of places a mention by Microsoft that WMI Performance counters are only a Windows 2K technology. Is this really true? If it is, what are we supposed to use going forward?
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
|
|
|
|
|
I have a few singleton classes which I would like to be truely single. i.e. I only want one instance between processes, users and sessions. I have found many articles on multithreaded singletons, but this does not address the memory scope problem. I could use a mutex to check for another instance, but what is the best way to share an instance?
|
|
|
|
|
There could be various solutions to this problem.
Preferrably using mutex's .
something like
HANDLE hMutex;
hMutex = CreateMutex(
NULL, // no security attributes
FALSE, // initially not owned
"SomeUniqueName"); // name of mutex
If this exists already return from the application.
Another option would be to use a shared variable and check for its value. Increment it each time an instance is created. If the value is greater than one you can just return from the second instance.
The third option would be to use the FindWindow function. You would get the handle to the window if it's already running.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Sorry if I didn't make it clear in my post. I am not talking about a single instance of an application, but infact a single instance of a class which is to be shared amongst multiple instances of an application.
|
|
|
|
|
waldermort wrote:
Sorry if I didn't make it clear in my post. I am not talking about a single instance of an application, but infact a single instance of a class which is to be shared amongst multiple instances of an application.
look for com classes!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|