IInternetProtocolRoot::Start is never called - windows

I am working on Asynchronous Pluggable Protocol Handler according to
https://msdn.microsoft.com/en-us/library/aa767916(v=vs.85).aspx#Creating_an_Asynchro
but step 3 is not happens. Urlmon.dll is supposed to call QueryInterface on my pluggable protocol handler for its IInternetProtocol interface and it does not. I am missing something and I can not figure it out. Does anybody know what the problem?
On step 2, ParseUrl is called twice:
if( ParseAction == PARSEACTION::PARSE_SECURITY_URL ) {
if( cchResult < _countof(L"http://localhost/") ) {
return S_FALSE;
}
memcpy(pwzResult, L"http://localhost/", sizeof(L"http://localhost/"));
*pcchResult = _countof(L"http://localhost/") - 1;
return S_OK;
}
if( ParseAction == PARSEACTION::PARSE_DOMAIN ) {
if( cchResult < _countof(L"localhost") ) {
return S_FALSE;
}
memcpy(pwzResult, L"localhost", sizeof(L"localhost"));
*pcchResult = _countof(L"localhost") - 1;
return S_OK;
}
return INET_E_DEFAULT_ACTION;

Related

How do I correct an error code 0 in MQL4 OrderModify() call?

I have this code below which I am using to test trailing stop function. It works on some currency pairs and doesn't work in others. It's returning error code 0 (zero). I will be grateful if somebody can help me out
void modifyTrade() {
TrailingStop = MarketInfo(Symbol(), MODE_STOPLEVEL);
if(TrailingStop>0)
{
for(int z = 0; z<OrdersTotal(); z++)
{
OrderSelect(z,SELECT_BY_POS);
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
bool res=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*TrailingStop,Digits),OrderTakeProfit(),0,Blue);
if(!res) {
Print("Error in OrderModify. Error code=",GetLastError());
//if(Symbol()=="EURNZD")
Alert("Error in OrderModify. Error code=",GetLastError()," ; ",OrderSymbol());
}
else {
Print("Order modified successfully.");
}
}
}
}
}
}
Error being
0 == ERR_NO_ERROR ... No error returned
is rather ok, no need to "correct" it, it means there was nothing to actually improve.
There are a few risky points to mention - prices move, STOPLEVEL parameter can either ( be careful on this - a hostile case if appears in live-trading ) and also be informed, that there are other levels, that may prohibit an OrderModify()-call from being Broker-T&C-compliant (and will get rejected for that reason)
Somehow improved code may work in this sense :
void modifyTrade()
{
TrailingStop = MarketInfo( Symbol(), MODE_STOPLEVEL );
if ( TrailingStop > 0 )
{
for ( int z = 0; z < OrdersTotal(); z++ )
{
if !OrderSelect( z, SELECT_BY_POS ) continue;
// ______________________________________________________ CRITICAL
RefreshRates();
// ______________________________________________________ Bid + Ask valid...
if ( TrailingStop != MarketInfo( OrderSymbol(), MODE_STOPLEVEL ) )
{ // TrailingStop CHANGED ... LOG, renegotiate such Broker policy
TrailingStop = MarketInfo( OrderSymbol(), MODE_STOPLEVEL
}
// ______________________________________________________ STOPLEVEL valid...
if ( Bid - OrderOpenPrice() > Point * TrailingStop
&& OrderType() == OP_BUY )
{
if ( OrderStopLoss() < Bid - Point * TrailingStop )
{
bool res = OrderModify( OrderTicket(),
OrderOpenPrice(),
NormalizeDouble( Bid - Point * TrailingStop, Digits ),
OrderTakeProfit(),
0,
Blue
);
if ( !res )
{
Print( "Error in OrderModify. Error code=", _LastError );
// if ( Symbol() == "EURNZD" )
Alert( "Error in OrderModify. Error code=", _LastError, " ; ", OrderSymbol() );
}
else
{
Print( "Order modified successfully." );
}
}
}
if ( OrderOpenPrice() - Ask > Point * TrailingStop
&& OrderType() == OP_SELL )
{
...
}
}
}
}
There are a couple of errors in your code.
once called, GetLastError() is reset. If you are both printing and alerting the last error, you should store the error code prior to printing/alerting.
you should check OrderSelect() succeeds.
you should iterate over orders in the opposite direction to ensure your code carried on operating should an order be closed mid-check.
You require different code for longs and shorts
Your code is prone to errors simply because you have no buffer and are trying to trail price at the minimum stop level. By the time your order modification is received by the trading server it is highly likely price may have moved back inside the stop level area resulting in a modification error.
void modifyTrade()
{
TrailingStop = MarketInfo(Symbol(), MODE_STOPLEVEL);
if(TrailingStop>0)
{
for(int z=OrdersTotal()-1; z>=0; z--)
{
if(OrderSelect(z,SELECT_BY_POS))
{
if(OrderType()==OP_BUY)
{
if(Bid-OrderStopLoss()>TrailingStop*point)
{
bool res=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*TrailingStop,Digits),OrderTakeProfit(),0,Blue);
if(!res)
{
int err=GetLastError();
Print("Error in OrderModify. Error code=",err);
Alert("Error in OrderModify. Error code=",err);
}
else Print("Order modified successfully.");
}
}
if(OrderType()==OP_SELL)
{
if(OrderStopLoss()-Ask>TrailingStop*point)
{
bool res=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Point*TrailingStop,Digits),OrderTakeProfit(),0,Blue);
if(!res)
{
int err=GetLastError();
Print("Error in OrderModify. Error code=",err);
Alert("Error in OrderModify. Error code=",err);
}
else Print("Order modified successfully.");
}
}
}
}
}
}

abort object3d.traverse in three.js

How can I abort the traverse when I traverse a three.js object?
scene.traverse(x => {
if (x.userData)
// stop traversing here
});
return and break do not work
Object3D.traverse code (r134)
You would need to modify the traverse function to bail based on output from your callback function.
Something like this (untested):
// three.js/src/core/Object3D.js
traverse( callback ) {
let bailedOut = callback( this );
if( !bailedOut ) {
const children = this.children;
for ( let i = 0, l = children.length; i < l && !bailedOut; i ++ ) {
bailedOut = children[ i ].traverse( callback );
}
}
return bailedOut;
}
And then call it like:
function doTheThing( node ) {
let bailOut = false;
if( node.userData ) {
bailOut = true;
}
else {
// do the thing
}
return bailOut;
}
scene.traverse( doTheThing );
The processing basically continues until your callback returns true, at which point it triggers a cascade back up the traverse recursion chain until it exits the original call.

how to check count of likes and dislike for post for rating sysytem

i am making an system to check count of likes and dislike if like count is more then dislike count then it gives true
but i am getting an error
// if (Files::withCount('likes') >= Files::withCount('dislike')) {
// return response()->json(['true']);
// }elseif (Files::withCount('dislike') >= Files::withCount('like')) {
// return response()->json(['false']);
// }else{
// return response()->json(['error'=>'somethingwenrwrng']);
// }
// if( DB::table('files')->select('files_id')
// ->join('likes','files_id.files_id','=','files_id') > DB::table('files')->select('id')
// ->join('dislike','files_id.files_id','=','files_id') ){
// return response()->json(['true']);
// }else {
// return response()->json(['error'=>'somethingwenrwrng']);
// }
$file = Files::find($id);
if($file ->likes->count() > $file ->dislike->count() ){
return response()->json(['true']);
}else{
return response()->json(['error'=>'somethingwenrwrng']);
}
i have tried different method to check but getting an error
the withCount() method return a property of the related field_count counting related models
so
$file = Files::find($id)->withCount(['likes','dislikes']);
if($file->likes_count > $file->dislikes_count ){
return response()->json(['true']);
}

C++ Visual Studio 2010 - Using Threads, Deque And Handlers

I'm trying to use multiple threads in an application that reads out of a large file.
I want to read from the file in the main thread and put each line into a deque called countedAddresses.
The I want multiple threads to pick lines out of countedAddresses and pull all of the email addresses out of them and place them in a deque called resolvedAddresses.
At the moment this all works if there is only one resolveAddressThread running, but if I run two I get heap corruption errors.
I launch the threads with:
_beginthread( resolveAddressThread, 0, NULL );
_beginthread( resolveAddressThread, 0, NULL );
Here is the thread code:
unsigned int linesCounted, linesResolved, linesProcessed;
std::deque<std::string> countedAddresses;std::deque<std::string> resolvedAddresses;
HANDLE linesCMutex, linesRMutex, linesRCMutex;
void resolveAddressThread(void* pParams)
{
string fileLine= "";
while(1)
{
WaitForSingleObject(linesCMutex, INFINITE);
WaitForSingleObject(linesRCMutex, INFINITE);
if (linesCounted>linesResolved)
{
if (countedAddresses.size()!=0)
{
fileLine = countedAddresses.front();
countedAddresses.pop_front();
ReleaseMutex(linesRCMutex);
ReleaseMutex(linesCMutex);
}
else
{
ReleaseMutex(linesRCMutex);
ReleaseMutex(linesCMutex);
Sleep(1000);
}
}
else
{ cout<<"All lines in the file have been processed."<<endl;
ReleaseMutex(linesRCMutex);
ReleaseMutex(linesCMutex);
break;}
if (fileLine.length()>1)
{
string::iterator strIter;
string buffer;
int tabCount=0;
bool useFlag =false, keepFlag = false, stopFlag = false;
buffer.clear();
for(strIter=fileLine.begin(); strIter!=fileLine.end(); ++strIter)
{
if (*strIter == '\t')
{
++tabCount;
}
if (tabCount == 10)
{
if ('\"'== *strIter)
{
useFlag=!useFlag;
}
else if (useFlag && *strIter > 0)
{
if (*strIter == '#')
{
buffer+=*strIter;
keepFlag = true;
}
else if ((*strIter ==' '||*strIter ==';')&& keepFlag)
{
if (buffer.at(buffer.length()-1)=='.')
{buffer = buffer.substr(0, buffer.length() - 1);}
WaitForSingleObject(linesRMutex, INFINITE);
resolvedAddresses.push_back(buffer);
ReleaseMutex(linesRMutex);
buffer.clear();
keepFlag = false;
}
else if (*strIter ==' '||*strIter ==';')
{
buffer.clear();
keepFlag = false;
}
else
{
buffer+=*strIter;
}
}
}
if (tabCount ==11 && keepFlag==true)
{
if (buffer.at(buffer.length()-1)=='.')
{buffer = buffer.substr(0, buffer.length() - 1);}
WaitForSingleObject(linesRMutex, INFINITE);
resolvedAddresses.push_back(buffer);
ReleaseMutex(linesRMutex);
buffer.clear();
keepFlag = false;
}
}
WaitForSingleObject(linesRCMutex, INFINITE);
++linesResolved;
ReleaseMutex(linesRCMutex);
fileLine.clear();
}
}
}
Please let me know where I am going wrong.
Thanks,
ANkh

kernel get stack when signalled

i write readers and writers where the kernel have to syncronize between them and block writer who already read a massage
when i am in the queue waiting I get signal so I do the fallowing
while (i_Allready_Read(myf) == ALLREADY_READ || isExistWriter == false )
//while (!(i_Allready_Read(aliveProc,current->pid)))
{
int i, is_sig = 0;
printk(KERN_INFO "\n\n*****entered set in read ******\n\n" );
if (i_Allready_Read(myf) == ALLREADY_READ )
wait_event_interruptible (readWaitQ1, !i_Allready_Read(myf));
else
wait_event_interruptible (readWaitQ1, isExistWriter);
//printk(KERN_INFO "Read Wakeup %d\n",current->pid);
for (i = 0; i < _NSIG_WORDS && !is_sig; i++)
{
is_sig = current->pending.signal.sig[i] & ~current->blocked.sig[i];
}
if (is_sig)
{
handledClose(myf);
module_put (THIS_MODULE);
return -EINTR;
}
}
return 0;//success
}
inline void handledClose(struct file *myf)//v
{
/*
*if we close the writer other writer
*would be able to enter to permissiones
*/
if (myf == writerpid )
{
isExistWriter = DOESNT_EXIST;
//printk(KERN_INFO "procfs_close : this is pid that just closed %d \n", writerpid);
}
/*
*else its a reader so our numofreaders
*need to decremented
*/
else
{
removeFromArr(myf);
numOfReaders--;
}
}
and my close does nothing ...
what did i do wrong?
Where are you waking up the wait queue?
You should be calling wake_up(readWaitQ1); somewhere. Possible after you set isExistWriter to true.

Resources