|
hi,
if you use a function like this where you give in strValue your "Lastname"
void FillSafeArray(CString strValue, int iRow, int iCol, COleSafeArray* sa)
{
VARIANT v;
long index[2];
index[0] = iRow;
index[1] = iCol;
VariantInit(&v);
v.vt = VT_BSTR;
v.bstrVal = strValue.AllocSysString();
sa->PutElement(index, v.bstrVal);
SysFreeString(v.bstrVal);
VariantClear(&v);
}
hope it helps,
DanielO
|
|
|
|
|
Thanks.
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
If i want to pass numerical value in FillSafeArray(int ivalue...)then what should i change in the FillSafeArray function?
Why i need int value because when i use FillSafeArray(CString strValue..) the value saved in excel sheet as text even though that value is "number". I want the sum of column & since the values are stored in excel as text in 1 column & if sum formula is used for that column in excel automation, it gives sum as 0. Hence i thought of storing this value as int so that am able to use sum formula in excel automation.
Is there any function to convert text to number in excel automation?
|
|
|
|
|
Hello
i have a MDI app derived from CFormView and i want when i "press" a menu item named Alimente to appear a new child window maximized and in it a CListCtrl ... i have tryed this in the my CChildFrame Class ... it appears normally until i try to selectem a list item or to press a column header .. it's really "dead" and when i change the window size the list is becoming erased in some places and the window's scroolbars white ... please help me to be normal and excuse my english
void CChildFrame::OnPersonalAlimente()
{
CProiectApp *aa=(CProiectApp*)AfxGetApp();
CCommandLineInfo cmdInfo;
aa->ProcessShellCommand(cmdInfo);
CMDIChildWnd * bb=((CMDIFrameWnd*)AfxGetMainWnd())->MDIGetActive();
bb->SetWindowText("ha");
WINDOWPLACEMENT vant;
bb->GetWindowPlacement(&vant);
vant.showCmd=SW_SHOWMAXIMIZED;
bb->SetWindowPlacement(&vant);
CRect rct(20,20,400,600);
aa->interfata.m_lcAlimente.Create(LVS_REPORT | LVS_SINGLESEL,rct,bb,567328);
aa->interfata.m_lcAlimente.SetWindowText("Alimente");
aa->interfata.m_lcAlimente.InsertColumn(0,"Aliment",LVCFMT_LEFT,100,0);
}
|
|
|
|
|
Hi.
I am learning about dll. I created a simple dll with one class and one member function that returns a string object. The function looks something like this.
-----
string MyClass::MyFunc()
{
string text = TEXT("Testing 1 2 3");
return text;
}
-----
In the main program, I statatically link the dll to the program. Everything compiles fine. However, the program crashes right after MyFunc().
-----
// Statically link DLL.
#include "MyDLL.h"
void MyWinClass::F1()
{
// Instantiate MyClass as local variable
MyClass oneVar;
// Attempt to get text from oneVar's member function
// MyFunc() should return a string object. It does.
string newText = oneVar.MyFunc();
-----
Everything works up to and including the last line of code. I could even open the text MyFunc() returns. There is a big problem, however; the program crashes.
This is the error Visual C++ shows when the program crashes after calling a function via the DLL.
-----
HEAP[MyProgram.exe]: Invalid Address specified to RtlValidateHeap( 00360000, 00353FA0 )
Unhandled exception at 0x77f7f570 in MyProgram.exe.exe: User breakpoint.
-----
In debug mode, the debugger shows a message box that mentioned something about "_BLOCK_TYPE_IS_INVALID(pHead->nBlockUsed)."
Is there something wrong with the dll? The algorithm above works find if I call MyFunc() from inside another class. It seems that the program is trying to free something after return from the dll.
Thanks,
Kuphryn
|
|
|
|
|
You try to free a memory block, allocated in DLL. It is wrong, because there are two heaps in your APP - first in EXE, 2'nd - in DLL. The memory block, allocated in DLL, must be freed in DLL only! I strongly discourage you to use STL routines with DLL. It is dangerous. You may use next approach instead of your example above
void MyClass::MyFunc(LPTSTR szText)
{
ASSERT(szText);
_tcscpy(szText,TEXT("Testing 1 2 3"));
}
Of course, it is not flexible 'cause you can't resize memory block on the fly in function MyClass::MyFunc, but ... I don't know another way to solve this problem.
May be, it is possible to use some compiler switches... I don't know
|
|
|
|
|
What Roman said is true and "strongly recommended": Always free resources in the same module scope you allocated them. This is simply a question of good and clean design.
Having said that there is also another solution.
The problem arises because you try to free a memory block that has been allocated by a different heap manager. This comes from linking CRT statically to the DLL and the .exe. Each of them, the DLL and the .EXE, have an own instance of the CRT and these two instances do not know anything about each other. Therfore the heap manager in the .exe is not able to free a block allocated via the heap manager in the DLL.
If you link both your app and your DLL against the same (Debug or Release) DLL version of the CRT, they will share one global CRT instance. This is because they both contain just a reference to the DLL and a DLL is always loaded only once into the process address space. Thus you can freely exchange CRT resources (memory blocks, FILE*, etc.) between your DLL and your .exe.
Note that this problem does not occur if you are using Win32 API resources. Because the Win32 API libraries are always DLLs you never run into the static linkage problem.
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
Thanks guys.
Wow. This is an interesting problem and is something I never expected.
First, why is it a bad design to return data back from a DLL? Is it a bad design to return an STL data structure back from a DLL?
What if you were to compile the DLL and EXE in one project instead of two separate projects?
I compiled the DLL in a separate project. Here is how I did it.
- project1 is DLL only
- project2 is EXE statically importing DLL
I thought it is okay to compile a dll separately and then using .dll, .lib, and .h files in any other project that will statically import the dll. Furthermore, you can use the .dll file in any project that dynamically imports the dll.
If the message I receive is what I believe it is, you need to compile all DLL and EXE in one project if and only if you want to statically import DLLs.
niyaw of GameDev mentioned something about setting the compiler for *multithreaded DLL runtime*. What is that about?
Kuphryn
|
|
|
|
|
Okay. I believe I see the problem. The problem has to do with setting the compiler (Visual C++ .NET) to compile both the DLL project and EXE project (both debug and release versions) to "Multi-threaded DLL /MD."
The solution above is from niyaw of GameDev. Everything works, except for one problem. I am using MFC doc/view as program core. I have set the compiler to "Use MFC in a Static Library." I believe when you set to that option, the compiler automatically changes "Multi-threaded DLL /MD" to "Multi-threaded /MT."
So the bottomline is that the original problem has to do with multithreaded DLL setting and can be fixed. However, if I fix that problem, I cannot use MFC via Static Library. That is okay too, but then I would have to gather all MFC dll into one zip file before releases the program. Some people do not have MFC DLLs.
Kuphryn
|
|
|
|
|
Hi,
I did see a program from MSDN sample Send Email with a Notepad npp.prj! After the user selecting Send option, the program opens an OutLook Express with an attached Notepad file (launch at the beginning)!
But what I need is a bit different! I would like to open the same OutLook Express but with a destinated user Email address (ie: thanhchau@videotron.ca) and with an existed attachment that I will insert at Run time (ie: c:\sample.txt)... without using any NotePad or any editor!
Any one has done it before? I will appreciate any codes or guidelines here!
Thanks & regards,
|
|
|
|
|
Oh, are you ever in Luck! Click here to download PJ Naughter's CMapi class. It will do all you need.
Note it is also here on CP, but it is an earlier version, so download the one at the link above.
---
Shog9
If I could sleep forever, I could forget about everything...
|
|
|
|
|
Hi Shog,
I did download and try, but I got stuck with the the project and have 11 errors after copiling:
One of them is: MailDlg.cpp(154) : error C2039: 'AddMultipleRecipients' : is not a member of 'CMapiMessage'
C:\SmartEmail\CMapi.h(24) : see declaration of 'CMapiMessage'
I did look into the class itself & really see that it does not have the member of the error C2039!
Did you try it before?
Thank for help, might be you know this problem & help me again?
ThanhChau
|
|
|
|
|
Hmm, that's odd. I've only used the version posted here, not the one on PJ's website; i just saw there was a later version there. But, you might as well try the version here:
http://www.codeproject.com/internet/cmapi.asp
If this one works, you should probably drop Mr Naughter a line to let him know about the problem with the newer version.
---
Shog9
If I could sleep forever, I could forget about everything...
|
|
|
|
|
Try using ShellExecute() to open this "document": "mailto:thanhchau@videotron.ca" .
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hi Ravi,
I did try as you suggest after the "mailto:thanhchau@videotron.ca". The problem it appear outside of the OutLook Express.
Might be I did not understand what you suggested: If some how it appear inside the contents of OutLook Express ---> OK! Would you please more specify on this!
Thanks a lot for help!
ThanhChau
|
|
|
|
|
Hmm, the ShellExecute() call should cause your default mailer to open. If it's not OE, then are you saying that you want OE specifically to deliver the message? Sorry if I put you on the wrong track!
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hi!
I need a safe way to acquire a colored bitmap... Now, I do it like
hDC = CreateCompatibleDC(NULL)
hBitmap = CreateBitmap(params...hDC...)
but it's still B&W
any ideas? Thanks!
PS: running 98 if you find this relevant. No window handle available
|
|
|
|
|
Can you post more or your code? What are you passing CreateBitmap for UINT cPlanes and UINT cBitsPerPel?
Todd Smith
|
|
|
|
|
CreateBitmap( width, height, GetDeviceCaps( hTempDC, PLANES ), GetDeviceCaps( hTempDC, BITSPIXEL ), NULL );
and I get the dc like
hTempDC = CreateCompatibleDC(NULL)
|
|
|
|
|
Check what GetDeviceCaps( hTempDC, PLANES ) and GetDeviceCaps( hTempDC, BITSPIXEL ) are returning. I suspect GetDeviceCaps( hTempDC, BITSPIXEL ) is not 8 or greater which is required for a color image. If you want a 256 color image then use 8 otherwise use 24.
Todd Smith
|
|
|
|
|
Hello. I'm using MFC without the use of any wizards or such (VC6/w2kpro), doing everything manually. Now I've run into a problem, I cant set message text to my status bar..here's my frame window constructor:
FrameWindow::FrameWindow()
{
Create(); // create the frame window
m_wndStatusBar.Create(this);
SetMessageText("Testing");
}
When I run this code, I see the status bar, but I don't see any text on it. Then I tried moving SetMessageText("Testing"); to FrameWindow::OnPaint(), and then the text appeared. Now, I dont want to call SetMessageText() in OnPaint(). Why can't I set the inital text in the frame window constructor?
I also tried with m_statusBar.GetStatusBarCtrl().SetText( "Testing", 255, 0 );
Same result as with SetMessageText().
Please help me solve this annoying problem
William Payne
|
|
|
|
|
Probably, it does not work that there are no created fields in SB. Try to use something looks like that:
... It's our SB fields
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_POS,
ID_INDICATOR_CAPS,
ID_INDICATOR_OVR,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
... Use update action handlers to change contents of SB
ON_UPDATE_COMMAND_UI(ID_INDICATOR_POS, cmdupOnIndicatorPOS)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_OVR, cmdupOnIndicatorOVR)
....
..... After SB creation we must set indicators
pStatusBar->SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));
...... Update it!!
void CSourceView::cmdupOnIndicatorPOS(CCmdUI* pCmdUI)
{
TCHAR str[32];
....
sprintf(str," Line %d, Col %d", dwLine+1,dwCol+1);
pCmdUI->SetText (str);
}
|
|
|
|
|
Tried your suggestions (except for the command handlers), still no text in the message pane. And I don't think the lack of panes was the problem, since text appears if I call SetMessageText() in OnPaint() of the parent window (the frame window). I've made a small test program: which is as follows:
///// APPLICATION.H /////
#ifndef APPLICATION_H
#define APPLICATION_H
#include <afxwin.h>
#include "FrameWindow.h"
class StatusBarApplication : public CWinApp
{
public:
BOOL InitInstance();
};
extern StatusBarApplication g_applicationInstance;
#endif
//// END OF APPLICATION.H ////
//// APPLICATION.CPP ////
#include "Application.h"
StatusBarApplication g_applicationInstance;
BOOL StatusBarApplication::InitInstance()
{
m_pMainWnd = new FrameWindow();
m_pMainWnd->ShowWindow( m_nCmdShow );
m_pMainWnd->UpdateWindow();
return TRUE;
}
//// END OF APPLICATION.CPP /////
//// FRAMEWINDOW.H /////
#ifndef FRAMEWINDOW_H
#define FRAMEWINDOW_H
#include <afxext.h>
#include <afxwin.h>
class FrameWindow : public CFrameWnd
{
public:
FrameWindow();
DECLARE_MESSAGE_MAP()
private:
CStatusBar m_statusBar;
};
#endif
//// END OF FRAMEWINDOW.H ////
//// FRAMEWINDOW.CPP ////
#include "FrameWindow.h"
BEGIN_MESSAGE_MAP( FrameWindow, CFrameWnd )
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
//ID_INDICATOR_POS,
ID_INDICATOR_CAPS,
ID_INDICATOR_OVR,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL
};
FrameWindow::FrameWindow()
{
Create( NULL, "Status Bar Test" );
m_statusBar.Create( this );
m_statusBar.SetIndicators( indicators,
sizeof( indicators ) / sizeof( UINT) );
SetMessageText( "test" ); // No text appears in the message pane
// despite this call.
}
//// END OF FRAMEWINDOW.CPP ////
|
|
|
|
|
What about CStatusBar::SetPaneText??? In my opinion it is best solution...
|
|
|
|
|
I am retrieving a text field from a database using the syntax that works fine for an ordinary text entry:
m_photoInfo = (_bstr_t)m_pRecordset->Fields->GetItem ("ID")->Value;
the problem here is that in the ID field I have a value C:\def.mdb,abc
When it gets this value out I have a messagebox pop up which tells me its horribly confused and has some garbage characters ef.mdb,abc
How do I get this text value out so that it comes out properly?
Thanks,
ns.
|
|
|
|
|