|
I am trying to call a VB function from VC++ which resides in a VB dll (using CreateDispatch and header from a type library to access the VB dll) that is declared as a "String" and then set the return value to some type of variable that will hold it in the VC++ calling code. I am able to make this handshake and display a messagebox and grab the integer value returned in another test function, so I know that I am talking to the dll, I think it is the darned string representation that is not straightforward.
I have tried to work CString, BSTR, using strcpy, = , whatever and have looked high and low for an example but cannot find what I want.
Does anyone know how to do this?
The generated cpp file present in the VC code that comes from the VB dll contains:
CString _ReadWritePath::LogPath()
{
CString result;
InvokeHelper(0x60030007, DISPATCH_METHOD, VT_BSTR, (void*)&result, NULL);
return result;
}
I am including the header file clslib14.h in the file doing the call,
and the VC++ call is:
_ReadWritePath p;
p.CreateDispatch("ClsLib14.ReadWritePath");
???????? = p.LogPath() // this is what I can't figure out
Effectively, how do I pass a VB's function return value (declared as String in VB 6 as a dll) to a call from VC++ 6 and set it to a local variable in the C++ code?
-Kirk
|
|
|
|
|
Kirk Woller wrote:
Effectively, how do I pass a VB's function return value (declared as String in VB 6 as a dll) to a call from VC++ 6 and set it to a local variable in the C++ code?
I believe you have to use a VARIANT for this.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I have done this but with out using invoke or com. I had a plain C++ DLL that I pased the address of a VB function into. As long as you declair the function pointer comming from VB as pascal works fine.
|
|
|
|
|
Try LPCSTR / LPSTR or _bstr_t any one of those will work. I Regularly use LPCSTR for passing strings into a C++ DLL.
-------------------------------
DEBUGGING : Removing the needles from the haystack.
-- modified at 2:37 Thursday 15th September, 2005
|
|
|
|
|
hi, all
I would get 0xC0000005: Access Violation, at the end of this code:
void Run(LPVOID dat)
{
CAddSurchrgDlg* cDlg = (CAddSurchrgDlg*)dat;
CString csWintext;
cDlg->GetWindowText( csWintext );
csWintext += " Version 1.02";
cDlg->SetWindowText( csWintext );
try
{
if ( !cDlg->m_bCanceled )
cDlg->ParseCommandLine();
if ( !cDlg->m_bCanceled )
cDlg->OpenFiles();
if ( !cDlg->m_bCanceled )
cDlg->AddNewSurcharges();
}
catch( ExceptionMsg e )
{
MessageBox( GetFocus(), e.errMsg, "Add Surcharge", MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
}
catch (CDataBaseException& e)
{
MessageBox(GetFocus(), e.what(), "Add Surcharge", MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
}
catch(...)
{
MessageBox( GetFocus(), "Unhandled Exception", "Add Surcharge", MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
}
cDlg->Exit();
on /MFC/THRDCORE.CPP, It crashes over here:
DWORD nResult = 0;
if (pThread->m_pfnThreadProc != NULL)
{
nResult = (*pThread->m_pfnThreadProc)(pThread->m_pThreadParams);
but if I use the same data and same switch to run this app on command prompt, it would work fine and create reports.....well, i just ran again, it crash, too. so it was just lucky to work sometimes.
anybody get idea why is that? Thank you!
-- modified at 15:54 Wednesday 14th September, 2005
|
|
|
|
|
valerie99 wrote:
cDlg->GetWindowText( csWintext );
cDlg->SetWindowText( csWintext );
This is a major no-no for a secondary thread to directly access a UI component that it does not own. The proper method is to post a message to the thread that owns the UI component. See here and here for more.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
but the access violation message still show up, in fact, it's a bit strange to me, seems like half of time, it would be memory leak and half of times would be access violation.
not sure if they are related...thanks for your time
|
|
|
|
|
what boolean operation does an AND gate and 2 NOR gates compute?
|
|
|
|
|
Isn't it AND ? Doesn't NOR reverse itself ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Oh good grief - are you too lost to even try and find the info?
You have heard of google? By me a donut and I'll tell you out right....
C. Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
|
|
|
|
|
Shantise2003 wrote:
boolean operation does an AND gate and 2 NOR gates compute?
Let A and B are two Digital Output NOW.....
A AND B Output
1 1 1
1 0 0
0 1 0
0 0 1
and about NOR A and B or ( A OR B = Output and THEN NOT the output)
A OR B Output NOT modified Output
1 1 1 0
1 0 1 0
0 1 1 0
0 0 0 1
hope this will brush up your mind
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Congratulations on your neat reply - guide the questioner but don't give the answer!
|
|
|
|
|
I wrote an app that will alert me when something happens after a certain amount of time. The app will also dump a file in a directory when it pops up with my alert message. The only problem is, it doesn't alert me if I minimize the dialog. It may still dump the file, I haven't been able to test that yet, but I want my app to still alert me and output this file even when minimized. Any help?
Thnx,
Danny
|
|
|
|
|
Can we see some code?
I've written apps along the same lines without an issue, regardless of being minimised (to the task bar or the system tray). If we can see some code maybe we can investigate.
How is the thing being triggered? An event / message / timer checking for "x" / thread checking for "x" etc.?
-Dy
|
|
|
|
|
When the dialog is created I use CWnd::SetTimer(0, 60000, NULL); and then I catch it with:
void CNewNotifyDlg::OnTimer(UINT nIDEvent) <br />
{<br />
OnRefresh();<br />
<br />
CWnd::SetTimer(0, 60000, NULL);<br />
<br />
CDialog::OnTimer(nIDEvent);<br />
}
OnRefresh() is my function to do my calculations and see if I should notify the user. I want this to run in the background, minimized the majority of the time, and then, if my app's logic dictates, I notify with AfxMessageBox("Hey, wake up!");
I didn't actually see the AfxMessageBox until I maximized the dialog (after I was informed that I had forgotten to do something in the office within a certain amount of time, Arrggh! ).
Danny
|
|
|
|
|
bugDanny wrote:
I didn't actually see the AfxMessageBox
Your timer is being called. Try turning your speakers on - you should hear a beep with each message box each time the timer is executed. The message box however, is in the foregound of your app, and your app is minimised - so you don't see it. (Your data file is still being written out right?)
You could do this:
if (IsIconic())<br />
{<br />
ShowWindow(SW_RESTORE);<br />
}<br />
in your timer, it will restore your dialog. Personally I don't think it's good form to be bringing windows up in front of the user like that, I'd rather minimise to the system tray and maybe use a balloon tooltip as a notification. You might want to have a look around this site for examples of that.
Again, should you be new to this... you don't need to call CWnd::SetTimer(0, 60000, NULL); in your OnTimer (and you don't need the CWnd:: bit in the first SetTimer call...)
-Dy
|
|
|
|
|
bugDanny wrote:
AfxMessageBox("Hey, wake up!");
Use MessageBox instead of the AfxMessageBox version. This should get you the desired results.
-------------------------------
DEBUGGING : Removing the needles from the haystack.
|
|
|
|
|
Is there a straight forward way to make a number like 123 and turn it into a string with left padded zeros.
Example "123" into 0000123
A way that does not require a silly loop like this.
CString strSecId;
strSecId.Format("%d", m_iSectionId);
while(strSecId.GetLength() < 7)
strSecId = "0" + strSecId; //left pad with zeros
thanks
|
|
|
|
|
Try "%.7d".
Don't try it, just do it!
|
|
|
|
|
Your code looks great until that last line. Try this:
strSecId.Insert(0, "0");
The first argument is the 0-based index of where you want to insert this string (we want it at the fron, hence the 0) and the second argument is the string to insert (a 0!)
Hope this helps!
Danny
|
|
|
|
|
Use:
strSecId.Format("%07d", m_iSectionId);
|
|
|
|
|
Don't I feel silly. Thank you.
|
|
|
|
|
Hi there,
I created a dll which creates a WH_CBT windows hook to subclass new windows.
The problem is the CBT_CREATEWND structure given as parameter to the CBTProc.
It includes a pointer to a CREATESTRUCT structure, where I need to check the lpszClass member to determine the type of window. Some values are less than 0xBFFF, so I can call GetAtomName() to get the class name, but there are also values bigger than 0xC000, which are no memory addresses. Spy++ says they are atoms, but atoms have to be less than 0xBFFF. Any ideas?
Regards,
Alex
Don't try it, just do it!
|
|
|
|
|
I’m trying to make a surface plot in a dialog based VC++ 6 application to display the data from a numerical simulation of a differential equation. I initially wrote the code using SetPixel() which works fine but takes a long time to draw and is the wrong way to do things I am told. So I am trying to write a bitmap to the screen to speed up the display time but I am hopelessly confused.
I believe my problem is with the BITMATINFO structure I am not sure how to deal with the fact that RGBQUAD is of size [1]? But I will leave that to your judgment.
What I currently have seems to work for most of the bitmap(it displays a gradient of gray as it should) but then random colors appear on the bottom of my screen (and I am not using the BITMAPINFO structure as I am sure I should).
Anyway the code I am using inside the OnPaint() event is :
CPaintDC dc(this);
int length = 8;
int size = length*length;
unsigned char *surface;
surface = new unsigned char[size];
CPalette temp_palette;
BITMAPINFOHEADER bmH;
bmH.biSize = sizeof(BITMAPINFOHEADER);
bmH.biWidth = length;
bmH.biHeight = length;
bmH.biPlanes = 1;
bmH.biBitCount = 8;
bmH.biCompression = BI_RGB;
bmH.biSizeImage = 0;
bmH.biXPelsPerMeter = 0;
bmH.biYPelsPerMeter = 0;
bmH.biClrUsed = 256;
bmH.biClrImportant = 0;
RGBQUAD pcolors[256];
LOGPALETTE *ppal = (LOGPALETTE *) new char[sizeof(LOGPALETTE) + 256*sizeof(PALETTEENTRY)];
ppal->palVersion = 0x300;
ppal->palNumEntries = 256;
for(int n=0; n< 256; n++){
ppal->palPalEntry[n].peBlue = pcolors[n].rgbBlue = n;
ppal->palPalEntry[n].peGreen = pcolors[n].rgbGreen = n;
ppal->palPalEntry[n].peRed = pcolors[n].rgbRed = n;
ppal->palPalEntry[n].peFlags = pcolors[n].rgbReserved = 0;
}
temp_palette.CreatePalette(ppal);
delete ppal;
//set surface to display a gradient and verify the code
for(n=0; n
|
|
|
|
|
Sorry everyone:
The data initialization loop was displayed incorectly It should be
for(n=0; n<size; n++){
surface[n] = (char)((int)(n/((double)size)*255));
}
|
|
|
|