|
You can try
[return: MarshalAs(UnmanagedType.LPStr)] However, that's going to be tricky: what frees the string?
If you control both the C# code and the DLL, I'd change your API so it takes a string pointer and a size:
BOOL GetDescr( int id, char* pBuffer, int bufLen )
{
if ( bufLen < LUNGHEZZA_STRINGA_MEM )
{
return FALSE;
}
else
{
strcpy( pBuffer, oggetto[id].descr );
return TRUE;
}
} then call from C# like so:
[DllImport( "WebUtility.dll", EntryPoint=GetDescr )]
public static extern bool UnsafeGetDescr( int id, StringBuilder buffer, int bufLen );
public static extern string GetDescr( int id )
{
StringBuilder sb = new StringBuilder( LUNGHEZZA_STRINGA_MEM );
if ( !UnsafeGetDescr( id, sb, sb.Capacity ) )
{
return null;
}
else
{
return sb.ToString();
}
}
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Ok, thank you vary much, using your suggestion I solved the problem!!
Matteo
|
|
|
|
|
Hi Friends,
Our product uses shell integration to extend the functionality of the explorer. when doing some internal operation i may get crash. Explorer then dies. Instead of try/catch in each functionality I need a generic solution so that i can do some cleanup at the time of crash.
(i)I tried with Hooking windows messages but i am not getting the quit/destroy message when the explorer crashes abrubtly(Terminate process)
(ii) I tried with some solutions in the internet for monitoring the process but it is complex with additional server / dll that is injected with all process. Also this solution causes performance difference.
Can any one of you please help me to find a simple solution so that i can handle this situation.
jothi
|
|
|
|
|
Have you tried some low level debuggers like softice or WinDBG?
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
Thanks for your reply.
Sorry, I dont know the usage of these debuggers.
Can you please explain more details about that.
jothi
|
|
|
|
|
|
the vertical scroll bar doesnt get enabled if i add string which doesnt fit a list box. Any ideas what seems to be the problem here. Horizontal scroll bar seems to work fine.
m_lstboxMessages.AddString(sServerMsg);<br />
UpdateData(FALSE);
where m_lstboxMessages is control variable of CListBox
Any suggestion regarding this??
|
|
|
|
|
Make sure that the Vertical ScrollBar property of your control is enabled. You should be able to see this in the resource view.
I Dream of Absolute Zero
|
|
|
|
|
yea its enabled infact i should have mentioned the styles that i have turned on...
Border=checked
Horizontal Scroll=checked
Vertical scroll=checked
Disable No Scroll=checked
No integral height=checked
any thing missing over here??
|
|
|
|
|
FASTian wrote:
the vertical scroll bar doesnt get enabled if i add string which doesnt fit a list box.
This indicates that the horizontal scroll bar is not working. The vertical scroll bar is not concerned with a string's length. It comes into play when there are more items in the control than can be displayed (e.g., the control can only show 10 strings but 15 have been added).
If I am correct, it sounds like you simply need to call SetHorizontalExtent() in the dialog's OnInitDialog() method..
FASTian wrote:
m_lstboxMessages.AddString(sServerMsg);
UpdateData(FALSE);
There is no need to (ever) call UpdataData() .
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
nopes thats not the case the horizontal bar shows correctly...
when i add a long string. It only shows a part of the string according to the vertical height i.e it just shows only the last 10 characters or something like that...
|
|
|
|
|
I think I understand, but a picture is worth 1,000 words. Can you provide one?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
any ideas how i can paste a pic over here???
|
|
|
|
|
You can't (that I know of). You'd need to upload one to your own Web site and provide a link for it here.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi
I am trying to print a CString to a file using C++ ofstream. What I do is something like this:
CString cstr = "This is a test";
std::ofstream fTest("TestCString.txt");
fTest << cstr;
fTest.close();
The problem is, the result in TestCString.txt is not the text "This is a test", instead it is something like 002F4BC4, which I couldn't make any sense out of it.
Could someone tell me what the problem is, and since the string in my project MUST use CString, is there a way to print it using ofstream without changing the CString class?
Thanks!
|
|
|
|
|
try
CString cstr = "This is a test";
std::ofstream fTest("TestCString.txt");
fTest << (LPCTSTR)cstr;
fTest.close();
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
fTest << (LPCTSTR)cstr;
TOXCCT >>> GEII power
|
|
|
|
|
When you typecast object of CString with LPCTSTR, internally overloaded operator LPCTSTR will get called. else explicily call function of CString class "operator LPCTSTR()"
This will convert CString object to Long Pointer To Constant String which is acceptable format for ofstream.
The chosen One
|
|
|
|
|
Hmmm, I tried your exact code (without the suggested cast) and it wrote "This is a test" to the file.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
You're using VS.NET 2002 or 2003, while the OP is using VC6. Something in either the standard library or in CString has changed enough to fix this issue between the two.
The changes to CString in MFC 7.x are extensive: it's now defined in an ATL header, for a start. It's also a template class: CString is a typedef for CStringT< StrTraitMFC< TCHAR, ChTraitsCRT< TCHAR > > >.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Mike Dimmick wrote:
You're using VS.NET 2002 or 2003, while the OP is using VC6...
Actually, I've never even seen VS.NET 2002 or 2003, let alone used either of them. I am using VS6.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I copied the OP's code into a new Win32 Console project in VC6 (selecting 'An application that supports MFC' from the Wizard). It produced the original output. Opening the project in VS.NET 2003, converting it and rebuilding produced the correct output.
The fault is that the compiler appears to be selecting the class member (of basic_ostream ) operator<<(const void*) for some reason. It's definitely calling CString::operator LPCTSTR to get the pointer whether you include the explicit cast or not.
Have you upgraded to Visual Studio 6.0 Service Pack 6, and could this be a solution to the problem?
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Mike Dimmick wrote:
Have you upgraded to Visual Studio 6.0 Service Pack 6...
Yes, I have SP6.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
You have to cast the CString to an LPCTSTR ala
fTest << (LPCTSTR)cstr;
So that the insertion operator uses the right overload.
If you're using unicode, (e.g., L"This is a test" or, _T("This is a test") and unicode is turned on), then you'll want to use a std::wofstream instead of std::ofstream. But you'll still need to cast cstr to LPCTSTR.
If you, like me, tried testing this with cout, try using wcout instead (the cast to LPCTSTR is still required).
|
|
|
|
|
Dear friends,
My brother's company have a PABX within their premises. They have asked me to develop a telephoning system for them.
i) How do I access the PABX,
ii) How do I recognise telephone numbers from the PABX
iii)How do I read from the PABX
iv) How do I write to the PABX
v) How do I connect an inside caller to the ouside reciept
Just using the computer and the PABX with no operator intervention.
I need both logic and syntax answers.
Yours
Lloyd.
|
|
|
|