Here is what I did, will it give me the same result? I just modified the input and output setting.
Code:
vOut.vt = VT_ARRAY|VT_UI1; // Set to array of binary mode for sending
vOut.parray = SafeArrayCreateVector(VT_UI1,0,134);// Create an array of 128 data + 6 misc bytes
ucArray=(unsigned char*)vOut.parray->pvData; // Cast the pointer to an array pointer
ucArray[0]=HEADER; // Head of package
ucArray[4]=0; // Meanwhile the package type will be data
while (curr->next) { // Move thru whole prepared package link list
curr=curr->next;
vOut.parray->rgsabound->cElements=curr->len+6;// Send only amount of data in that package
ucArray[1]=curr->len; // Using casted array to store len and addr
ucArray[2]=curr->start/0x100;
ucArray[3]=curr->start&0xFF;
memcpy(&ucArray[5],&memCont[curr->start],curr->len);// Copy data to sending array
ucArray[curr->len+5]=curr->chksum;
WriteFile(hCom,vOut.parray,sizeof(vOut.parray),&iBytesWritten,NULL);
// pCommCtrl->SetOutput(vOut); // The actual sending (pass to it variant structure)
do {
while (!ReadFile(hCom,&sBuffer,20,&iBytesRead,NULL));// Wait for receiving
// ch=pCommCtrl->GetInput();
// ReadFile(hCom,&ch,20,&iBytesRead,NULL);
} while (ch!=ACKNOWLEDGE); // Wait for acknowledge character
}
vOut.parray->rgsabound->cElements=6; // Same thing send the last package (termination)
ucArray[1]=ucArray[2]=ucArray[3]=0x00;
ucArray[4]=0x01;
ucArray[5]=0xFF;
WriteFile(hCom, vOut.parray,sizeof(vOut.parray),&iBytesWritten,NULL);
// pCommCtrl->SetOutput(vOut);
SafeArrayDestroy(vOut.parray);