|
|
Just code your program to expect a command-line argument. When you run your program from inside of another, you would supply said argument. Those that save your program to try and run elsewhere would not know that it required a command-line argument nor what it should be. Make sense?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
this looks like an alternative solution to the problem.
thnx a lot.
|
|
|
|
|
uufff... as you know there are programs that decode the passwords for compressed files... moreover, surely there are lots of ways to get access to that exe while it is loaded...
I don't know, let's see if somebody can help you... I can't...
|
|
|
|
|
Hello everybody!
my thread application gets hang. can anybody help me welcome for sharing the code.
"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India
|
|
|
|
|
Can you explain more?
Cheers,
Suresh
|
|
|
|
|
sure dear !
actually i have been waiting for anybody's replay.thanks
well I have made list view in that list view there are suppose some files. I have started the batch mode protection . I have to use threading for that.
how can I do?
the code is below.
hwndListbox=hList;
LRESULT ListBoxItemCount=ListView_GetItemCount(hwndListbox);
int iSelectedFile1=ListView_GetSelectedCount(hwndListbox);
int iSelectedFile=SendMessage(hList,LVM_GETNEXTITEM,-1,LVNI_SELECTED);
if(ListBoxItemCount > 0)
{
for(int i=0;i<ListBoxItemCount;i++)
{
ListView_GetItemText(hwndListbox,i,1,(LPWSTR)&szBuffer,MAX_PATH);
ListView_GetItemText(hwndListbox,i,3,(LPWSTR)&szBuffer2,MAX_PATH);
string inputFile2= util.ConvertWCHARToString(szBuffer2);
string filenamewithpath = util.ConvertWCHARToString(szBuffer);
string inputFile=inputFile2+"\\"+filenamewithpath;
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,inputFile.c_str(),(int)(inputFile.length() + 1),bufferwithpath,MAX_PATH);
UINT Iselected=ListView_GetSelectedCount(hList);
unsigned threadID;
Utility util;
string outputfile=PrepareOutputFile(hDlg,util.ConvertWCHARToString(bufferwithpath));
WCHAR w_Output[MAX_PATH];
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,outputfile.c_str(),(int)(outputfile.length() + 1),w_Output,MAX_PATH);
struct argument_list l;
l.pszInFile=bufferwithpath;
l.pszOutFil=w_Output;
l._ProtectSet=_ProtectSet;
l.hList=hList;
l.Host=HOST;
l.hwndEncrypt=hwndEncrypt;
l.hWndinoutfiledir=hWndinoutfiledir;
l.hwndParent=hDlg;
l.InitPackageRequest=sINIT_PACKAGE_RESPONSE;
l.Port=PORT;
l.ScriptFile=COMMUNICATOR_SCRIPT_FILE_PATH;
l.UserID=UserID;
<big>hThread=(HANDLE)_beginthreadex(NULL, 0, &Thread ,&l,NULL, 0);</big>
}
WaitForSingleObject( hThread, INFINITE );
unsigned __stdcall Thread(void* pArguments )
{
HRESULT hr;
struct argument_list *Lparam= (argument_list *)pArguments ;
Package pkg;
<big>hr=pkg.EncodeMediaContent(Lparam->pszInFile,Lparam->pszOutFil,Lparam->hwndParent,Lparam->Host,Lparam->UserID,Lparam->InitPackageRequest,Lparam->ScriptFile,Lparam->Port,Lparam->hList,Lparam->_ProtectSet,Lparam->hWndinoutfiledir,Lparam->hwndEncrypt); </big>
if(hr==S_OK)
{
MessageBox(0,L"thread gone finished" ,L"therad",0);
_endthreadex( 0 );
}
return 0;
}
"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India
|
|
|
|
|
Why use a separate thread if you are just going to wait for it to finish?
If it's hanging then you can break execution in the debugger and examine the call stack(s)
to see where it's hanging.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I got your code (email) and right away I noticed your struct argument_list l; variable that
you are passing to your thread isn't static or global so it goes out of scope while the thread is
running. That's a big problem
Instead of making it global, maybe allocate the object with new and pass the pointer to the
thread. The thread can delete it when it's done with it or the thread can notify the calling
thread somehow and let the calling thread delete it - whatever works best for your application.
I'll let you know if I find anything else.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I just got an email saying I have responded to myself here[^]
That message was meant for you.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hello,
I've made a function that uses a BSTR, and returns it type casted as a CString.
Something like that:
CString Myfunc()<br />
{<br />
BSTR a;<br />
somefunc(&a);<br />
return (CString)a;<br />
}
And then I use that in order to set the returned CString as the text of a CEdit:
CEdit B;<br />
B.SetwindowtextA(MyFunc());
Is there any way that this could be generating a memory leak?
As always thank you in advance.
|
|
|
|
|
That code will leak memory.
Steve
|
|
|
|
|
OK, how should I avoid it?
Thank you for your feedback.
|
|
|
|
|
It could - depending on how the BSTR is managed... BSTR s normally transfer ownership, so when somefunc(...) places a BSTR into the passed variable, it likely transferred ownership of that copy of the BSTR . You would have to free that BSTR to prevent a leak (note that this kind of leak may not be reported by the debugger). Using a CComBSTR will take care of freeing it for you, BTW. So basically, if you are handing the BSTR correctly, your code will leak, and if you are handling it incorrectly, you might not leak!
If all you are doing is putting that value into an edit control, you can take advance of the fact that a BSTR is a wide string behind the scenes and can directly call SetWindowTextW( HWND, LPCWSTR ) to copy the data in the BSTR directly to the edit control, saving the overhead of the temporary CString . May not be a big difference in your application, but efficiency a good habit to get into IMHO.
{
CComBSTR bstrSomeValue;
CEdit B;
somefunc( &bstrSomeValue );
::SetWindowTextW( B.m_hWnd, bstrSomeValue );
} Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Hi
How to create two splitbars in VC++?
|
|
|
|
|
Using MFC CSplitterWnd?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
please help me this code logic
where make I the mistake this code
It is running console wizard in C++ but I trasformation to form enviroment borland C++ 6.0
i hope to your find to my mistake
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include "Unit1D.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
#define MAXPOP 25
struct gene {
int alleles[4];
int fitness;
float likelihood;
// Test for equality.
operator==(gene gn) {
for (int i=0;i<4;i++) {
if (gn.alleles[i] != alleles[i]) return false;
}
return true;
}
};
class CDiophantine {
public:
CDiophantine(int, int, int, int, int);
int Solve();
gene GetGene(int i) { return population[i];}
protected:
int ca,cb,cc,cd;
int result;
gene population[MAXPOP];
int Fitness(gene &);
void GenerateLikelihoods();
float MultInv();
int CreateFitnesses();
void CreateNewPopulation();
int GetIndex(float val);
gene Breed(int p1, int p2);
};
CDiophantine::CDiophantine(int a, int b, int c, int d, int res) : ca(a), cb(b), cc(c), cd(d), result(res) {}
int CDiophantine::Solve() {
int fitness = -1;
srand((unsigned)time(NULL));
for(int i=0;i<maxpop;i++) {
="" for="" (int="" j="0;j<4;j++)" population[i].alleles[j]="rand()" %="" (result="" +="" 1);
="" }
="" }
="" if="" (fitness="=" createfitnesses())="" return="" fitness;
="" int="" iterations="0;
" while="" !="0" ||="" <="" 50)="" generatelikelihoods();
="" createnewpopulation();
=""
="" iterations++;
="" -1;
}
int="" cdiophantine::fitness(gene="" &gn)="" float="" total="ca" *="" gn.alleles[0]="" cb="" gn.alleles[1]="" cc="" gn.alleles[2]="" cd="" gn.alleles[3];
="" gn.fitness="abs(total" -="" result);
}
int="" cdiophantine::createfitnesses()="" avgfit="0;
" fitness="0;
" for(int="" i="0;i<MAXPOP;i++)" 0)="" i;
="" 0;
}
="" cdiophantine::multinv()="" sumi="0;
" k="10;
" {
="" k;
="" sumi;
}
void="" cdiophantine::generatelikelihoods()="" multinv="MultInv();
" last="1;
" aktr="1;
" ((1="" (population[i].fitness)="" multinv)="" 100);
="" last+="last;
" }
}
int="" cdiophantine::getindex(float="" val)="" (last="" &&="" val="" else="" 4;
}
gene="" cdiophantine::breed(int="" p1,="" p2)="" crossover="rand()" 3+1;
="" first="rand()" 100;
="" gene="" child="population[p1];
" initial="0," final="3;
" (first="" {="" child.alleles[i]="population[p2].alleles[i];
" (rand()="" 101="" 5)="" child;
}
void="" cdiophantine::createnewpopulation()="" temppop[maxpop];
="" parent1="0," parent2="0," while(parent1="=" population[parent1]="=" population[parent2])="" 101));
="" (++iterations=""> 25) break;
}
temppop[i] = Breed(parent1, parent2); // Create a child.
}
for(int i=0;i<maxpop;i++) population[i]="temppop[i];
}
//---------------------------------------------------------------------------
__fastcall" tform1::tform1(tcomponent*="" owner):="" tform(owner)
{
}
="" ---------------------------------------------------------------------------
void="" __fastcall="" tform1::button1click(tobject="" *sender)
{
int="" solve();
int="" fitness;
edit1-="">Text=StrToInt(fitness);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
CDiophantine dp(1,2,3,4,30);
gene gn;
int ans;
ans = dp.Solve();
if (ans == -1) {
//cout << "No solution found." << endl;
} else {
gene gn = dp.GetGene(ans);
Memo1->Text= gn.alleles[0];
}
}
//---------------------------------------------------------------------------
|
|
|
|
|
oz-gur wrote: i hope to your find to my mistake
i hope nobody will, and that you'll learn to use your debugger and learn also how to ask a question on a forum propery
|
|
|
|
|
I keep reading articles which say virtual function has overhead on performance, but I'd like to know how much is it?
For example, the MFC framework, if all the functions inside are virtual, how much will MFC's performance decrease, for the current 1GHz/512M PC hardware ?
|
|
|
|
|
Yes there is overhead on performance. But it is very important to understand the virtue/performace relation when using virtual functions. I mean, one should avoid using virtual functions in low level operations such as accessing each character in a sequence. But for not so heavy and/or intensive operations you can [and sometimes should] ignore performance issues.
As for MFC, a good candidate area of using virtual functions is message handlers. But MFC refused virtual functions and used message maps. Really, so many classes with so many virtual functions would indeed decrease speed and increase memory usage.
--
=====
Arman
|
|
|
|
|
Dear all
How I can make a tooltip for a button in Visual C++ 6. The message should be dynamic. I want to change it on the fly(at run time).
Best regards
|
|
|
|
|
|
Thanks
It was what I need.
|
|
|
|
|
hi guys,
DO anyone know what is the reason that i can only play avi file which is original in Microsoft, but when i import a avi format from external i cannot play it..
How can i play my avi in animation control by displaying it full on the screen?
Pls advice, am using VC++ 2003 MFC.
Thanks ..
|
|
|
|
|
I think Animation Controls [^] will be helpful for you and also it has description of this control
|
|
|
|
|