|
So you want to pass the data to a C++ routine after it has been extracted by the VB program, or you just want to translate all of the VB code into a C++ program?
|
|
|
|
|
I just want to translate the VB code into C++ program. It's a bit difficult on my part.
Thanks
|
|
|
|
|
Hi Kuroro,
How about fscanf ?
Regards,
Chris
|
|
|
|
|
I'm currently studying string extractions. I can't focus really on software side coz i'm also designing the hardware...
Thanks Chris, I'll be trying it....
|
|
|
|
|
What does the dots at the end of each line signify?
Steve
|
|
|
|
|
char char_val;
int int_val1, int_val2, int_val3;
long int longint_val1;
char comma;
ifstream fs("C:\\a.txt");
if ( !(fs >> char_val >> comma) || comma!=',')
{
}
if ( !fs >> int_val1 >> comma) || comma!=',')
{
}
Steve
|
|
|
|
|
Steve,
Sorry for the dot stuff, that signifies another input of type long int... actually the first entry is Char, then the second, third and the fourth is of type int, the fifth until end of line is a type of long int. each line have different number of items.
I'm not good in explaining things.
Thanks Steve
|
|
|
|
|
Thanks a lot Steve, I'm currently coding it in my C++ BuilderX compiler.
Thanks........
|
|
|
|
|
To me, each line looks like a struct constisting of a std::string , 3 ints and a std::vector of longints.
The constructor of this struct can take a line of the file, parse it and fill the fields.
getline would be the method to - erm - get the line from the file.
For parsing, you could use fscanf or look at e.g. www.boost.org[^]for a parsing library.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
Steve,
Actual items in the file M637.VIN
M2,2,1,15,55342,55662,55982,56302
A,4,1,15,58856,59176,59496,59816
P,5,1,15,55327,55647,55967
B,7,1,15,55310,55630,55950,56270
4B,8,2,15,27769,25530
General format:
char_val,int_val1,int_val2,int_val3,longint_val1
is it possible to store these stuff in a struct or an array of some sort? Coz i need int_val1 and int_val2 as a reference to an output port. in line 1 "M2,2,1" , i need to access the extracted input 2 and 1 coz it corresponds to an output port2 and port1.
on the other hand, char_val must be taken into account coz it serves as a reference to longint_val(n).
Thanks,
Kuroro
|
|
|
|
|
Hi Coders
I have a Visual C++ 2005 solution made up of two projects with lots of source fles (containing functions only) that produce two separate dlls.
In one source file I calculate a value in a variable and I want that variable to have global scope across the two projects. Is that possible? The value in the variable is needed by all the other functions in the two projects to work properly.
I have tried declaring the variable in header file and before the call to dllmain but neither approach works. I can't use a macro because the I have to recalculate the value each time the dlls are used.
Any suggestions would be much appreciated.
Regards
Jeremy
|
|
|
|
|
Hi Jeremy,
I didn't catch your question very well. If u r talking about two dlls that are called by one executable module, which means that they are running in the same process, I would like you try to declare a variable in the exe file, pass a pointer to it to both dlls and reference this variable to share info.
If they are running in different processes, I would suggest you use some ipc apporach, for example Create/OpenFileMapping thing.
Regards,
Chris
|
|
|
|
|
Thanks Chris
That's right I have two dlls that are called by one executable (Excel). I wanted to keep the variable out of Excel/VBA and just pass it between functions within both dlls. I'm very new to programming.
Regards
Jeremy
|
|
|
|
|
I can see this solution:
In the first DLL, define a function that returns a pointer to your variable. In the other DLL, dynamically load the first DLL with a call to LoadLibrary, and call the aforementioned function.
Rich
|
|
|
|
|
Thanks Rich
That sounds like the way to do it. I'll have a go at it. The variable may, however, revert to null once the function that performs the calculation goes out of scope.
Regards
Jeremy
|
|
|
|
|
Hi Jeremy,
I am new to programming too. I think it is really cool to code something in MS Office. I mean that.
Well, I think neither of my suggestions work in your case. Em... is your variable accessed very frequently? I mean, how about use registry table to story this variable?
The following example really do very well in registry access stuff.
http://www.codeproject.com/system/CRegistry.asp[^]
Regards,
Chris
|
|
|
|
|
Hi,
Is there a problem writing to a CSocket from a different thread than the one that created it?
I am sending large files so I use a worker thread to do the writing, but it ASSERTS when it check the handle for the socket.
If I call the code from the same thread it seems OK.
TIA
Tony
|
|
|
|
|
Don't take this as the final word on the subject, but I do remember reading specifically in the MFC docs that MFC objects cannot be shared between threads.
( I know, this is a real bummer. )
The solution is to pass the handle of the underlying socket to the worker thread, and then have the worker thread create a new CSocket, and Attach() the passed handle.
Hope this helps,
Rich
|
|
|
|
|
Hi,
Thanks for the quick reply. You know I think you are right there, I should have realised becasue I have seen similar problems before with MFC objects!
I will try it the way you have suggested tomorrow. Right now I need sleep
Thanks again
Tony
|
|
|
|
|
When you wake up, here is some reading for you straight from the MSDN Library:
Windows Handle Maps
As a general rule, a thread can access only MFC objects that it created. This is because temporary and permanent Windows handle maps are kept in thread local storage to help maintain protection from simultaneous access from multiple threads. For example, a worker thread cannot perform a calculation and then call a document's UpdateAllViews member function to have the windows that contain views on the new data modified. This has no effect at all, because the map from CWnd objects to HWNDs is local to the primary thread. This means that one thread might have a mapping from a Windows handle to a C++ object, but another thread might map that same handle to a different C++ object. Changes made in one thread would not be reflected in the other.
There are several ways around this problem. The first is to pass individual handles (such as an HWND) rather than C++ objects to the worker thread. The worker thread then adds these objects to its temporary map by calling the appropriate FromHandle member function. You could also add the object to the thread's permanent map by calling Attach, but this should be done only if you are guaranteed that the object will exist longer than the thread.
Another method is to create new user-defined messages corresponding to the different tasks your worker threads will be performing and post these messages to the application's main window using ::PostMessage. This method of communication is similar to two different applications conversing except that both threads are executing in the same address space.
For more information about handle maps, see Technical Note 3. For more information about thread local storage, see Thread Local Storage and Using Thread Local Storage in the Platform SDK.
|
|
|
|
|
I am trying to implement print and print-preview into a non-MFC application. After a little effort I have managed to create the print-preview function and a non working print function.
I have created a function which is passed a rect for the dimensions and a hdc, this function then creates and returns a HBITMAP compatible with the hdc and the size stated in the rect. I hope to use this function for both print and print preview.
The print preview is simply a dialog box, the HBITMAP is then drawn into the client area.
I'm having problems now trying to correctly draw this bitmap to the hdc returned by printDlg(). I have read all of the (MFC only) projects here on codeproject, but I am left even more confused. I know that I need to stretch the bitmap but all I am left with is a tiny black square.
This is a portion of the print function:
printRect.bottom = GetDeviceCaps(pd.hDC, HORZRES);
printRect.right = GetDeviceCaps(pd.hDC, VERTRES);
StartDoc(pd.hDC,&di);
StartPage(pd.hDC);
HBITMAP table = create_printable_table(pd.hDC,&tmprect,rec);
SelectObject(buf,table);
StretchBlt(pd.hDC,0,0,printRect.right,printRect.bottom,buf,0,0,tmprect.bottom,tmprect.right,SRCCOPY);
EndPage(pd.hDC);
EndDoc(pd.hDC);
Please help me with this one, I have spend far too long splitting hairs
-- modified at 14:02 Sunday 19th March, 2006
|
|
|
|
|
I had a similar problem with one of my projects. Read up on these functions:
SetMapMode(MM_ISOTROPIC);
SetWindowOrg(m_BmpInfo.bmWidth / 2, m_BmpInfo.bmHeight / 2);
SetViewportOrg(pDC->GetDeviceCaps(HORZRES) / 2, pDC->GetDeviceCaps(VERTRES) / 2);
SetWindowExt(m_BmpInfo.bmWidth, m_BmpInfo.bmHeight);
SetViewportExt(pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Most printer DC's dont support bitblt. You need to use StretchDIBits. Thats why it works in preview (a screen DC) and not in print mode.
If you vote me down, my score will only get lower
|
|
|
|
|
Hope I understood your question
you need to print bitmap
HDC hdcPrint=CreateCompatibleDC(
CreateDC(pPrinter->pDriverName,(LPCTSTR)lpdevmode->dmDeviceName,pPrinter->pPortName,lpdevmode));
...
...
...
//function print
{
DOCINFO di;
memset((void *)&pd, 0,sizeof(PRINTDLG));
pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = this->m_hWnd;
pd.Flags =PD_RETURNDC|PD_ENABLESETUPTEMPLATE;
pd.hInstance = NULL;
pd.nMaxPage=1;
pd.nMinPage=1;
pd.nCopies=1;
pd.hDevMode=lpdevmode;
pd.nFromPage=1;
pd.nToPage=1;
PrintDlg(&pd);
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "Job";
di.lpszOutput = NULL;
SelectObject(hdcPrint,hBitmap);
StartDoc (pd.hDC, &di);
StartPage (pd.hDC);
BitBlt(pd.hDC,150,300,2100,1575,hdcPrint,0,0,SRCCOPY);
EndPage (pd.hDC);
EndDoc (pd.hDC);
DeleteObject(hBitmap);
}
maybe it is some helpful to you
|
|
|
|
|
Hi,
I am working with tool set template (C++ code for Vis.Stu. 6.0). I will pattern my own code after this template.
The template calls a DLL.
In the past when I have called DLLs from my code I have used the:
LoadLibrary(something.DLL);
But I can't find anywhere in the project's code (all the .cpp. .h .c files) where the DLL is loaded.
When I compile the app everything wokes fine so the DLL is working.
Also, when I do a text search on the project directory, I do indeed find the DLL in the files:
.ilk .plg .dsp .pdb and the .exe
I just can't dinf, within the Visual Studio user interface, where the DLL is declared/called/loaded.
Many thanks,
Robert
|
|
|
|
|