Hello! I'm Servo Wizard.
I'm an accomplished VB6 programmer who is attempting to learn the C-C++ programming language. This project is my very first DLL and it is also the extent of my C programming experience. I proto-typed the functions in a console project and then moved on to the DLL.
1st major obstacle was figuring out how to return something that VB could digest. There was no way that I know of to export 21 digits other than a string. After 3 days of extensive research I learned how to export a string that VB would accept.
OK! End of 1st major obstacle, start of 2nd MAJOR OBSTACLE. When called from VB app it returns a string of 21 digits, all being the correct value when split into 7 individual values. I'm calling the DLL from a timer sub in VB and I noticed that the values were not varying as they occasionally should. It did not take to long to find that my string of 21 digits returned as 42 digits, 84 digits, 168 digits and so on until the MS error message arrived. It's quite obvious that the DLL does not close between calls.
I have spent the entire Labor day weekend trying to learn how to erase, free or whatever method is used to unload the 2 arrays in my DLL so as to prevent the compounding of the export string. Now, I sure that I have looked right at the solution several times but did not recognize it due to my inexperience with the C language.
It's not my style to have some one else do my learning and thinking for me but I would really appreciate some help with this problem.
Servo
Code:#include "myheader.h" char NxtBt[22]; char Bytes[22]; int Something; HANDLE h; BOOL APIENTRY DllMain ( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } BSTR __stdcall This() { if(Something) { strcat(Bytes, "0"); } itoa(_inp(Blank),NxtBt,10); // decimal value of 4Bh as string "075" strcat(Bytes,NxtBt); // array[0]="075" // repeats the following conditional 5 times with different value (Blank) each time. if(_inp(Blank)<100) { strcat(Bytes, "0"); } itoa(_inp(Blank),NxtBt,10); strcat(Bytes,NxtBt); // Bytes[0-2]="075";Bytes[3-5]="0??" ; and so on to Bytes[18-21]="0??" } return SysAllocString((OLECHAR*)Bytes); SysFreeString((OLECHAR*)Bytes); }