|
Issue is control is not comming in to the
catch(CArchiveException* e) block while debuging.. but still CArchiveException is thrown.
soe if CArchiveException is thrown.. then the control should come to catch(CArchiveException* e) right ? That is not happninig 
|
|
|
|
|
You have no code in your catch block so there is nowhere for it to go. Add some code and try again, at least you will be able to inspect the contents of the exception object.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
In the actual code I had few lines extrating the exception message and logging it.
but in the code I posted it was not there.... but controls never enters the catch block, even though the code was there and exception it throws was same ie (CArchiveException* e)
|
|
|
|
|
Once you have added actual code to the catch blocks, try running outside your IDE. Some, like Visual Studio, sometimes intercept exceptions before your catch block becomes active, although you typically can influence that through some IDE settings.
|
|
|
|
|
You're catching a pointer to CArchiveException, shouldn't you catch a reference to it?
ex. catch(CArchiveException & e) or maybe catch(CArchiveException const & e)
John
|
|
|
|
|
See here[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hi!
I'm stuck with the calling that DLL.
Can someone help me how to read the values of the DLL? OCIOpen of the opening returns sucess, but that reading doesn't work.
I guess... The problem is unmanaged/managed, but I don't how to solve it.
************ Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at WindowsFormsApplication3.Form1.oci.OCIRead(Int32 lOIObject, Int32 lDevice, Int32 lIndex,
OCIRead or OCIGetIndexInfo doesn't work.
using System.Runtime.InteropServices;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
[StructLayout(LayoutKind.Sequential)]
public struct OIDATA
{
[MarshalAsAttribute(UnmanagedType.SafeArray, SafeArrayUserDefinedSubType = typeof(Int32))]
public Int32[] lData; //'array of data, values depeds of index number
public Int32 lCheckAlarm; //'when read request is done and this is > 0 user should check alarm
public Int32 lCategory; //'when this is > 0 device configuration is changed
public Int32 lReadError; //'read error is occured
[MarshalAsAttribute(UnmanagedType.SafeArray, SafeArrayUserDefinedSubType = typeof(byte))]
public byte[] szData; // 'String * 128 'raw index read data as comma separated
}
/*
[StructLayout(LayoutKind.Explicit)]
public unsafe struct OIDATA
{
[FieldOffset(0)]
public fixed Int32 lData[32];
[FieldOffset(128)]
public Int32 lCheckAlarm;
[FieldOffset(132)]
public Int32 lCategory;
[FieldOffset(136)]
public Int32 lReadError;
[FieldOffset(140)]
public fixed byte szData[128];
}
*/
public OIDATA pOIDATA = new OIDATA();
public Int32 lObject = 0;
public Int32 lComPort = 5;
public Int32 OCI_OUTDOORTEMP = 3;
public Int32 OCI_MIN_INDEX = 0;
public Int32 OCI_MAX_INDEX = 63;
public sealed class oci // api // DLL Wrapper
{
internal const string DllName = "oci200.dll"; // handy const
[DllImport(DllName)]
public static extern Int32 OCIOpen(ref Int32 lOIObject, Int32 lComPort);
[DllImport(DllName)]
public static extern Int32 OCIRead(Int32 lOIObject, Int32 lDevice, Int32 lIndex, [param: MarshalAs(UnmanagedType.Struct)] ref OIDATA pOIData);
// _EXPORT(long) OCIGetIndexInfo(long lIndex,char **pszInfo,long *plRead,long *plWrite);
[DllImport(DllName)]
public static extern Int32 OCIGetIndexInfo(Int32 lIndex ,
[In, MarshalAs(UnmanagedType.LPStr)] System.String pszInfo,
ref Int32 plRead, ref Int32 plWrite);
}
private void cmdConnect_Click_1(object sender, EventArgs e)
{
Int32 l = oci.OCIOpen(ref lObject, lComPort);
lstOuman.Items.Add("OCIOpen: " + l);
pOIDATA.lData = new Int32[32];
pOIDATA.lCategory = 1;
pOIDATA.lCheckAlarm = 0;
pOIDATA.lReadError = 0;
pOIDATA.szData = new byte[128];
Int32 lIndex = OCI_OUTDOORTEMP;
Int32 lDevice = 2;
System.String pszInfo ;
Int32 plRead = 0;
Int32 plWrite = 0;
//pOIDATA.szData[127] = 0;
Int32 k = oci.OCIRead(lObject, lDevice, OCI_OUTDOORTEMP, ref pOIDATA); //This is where error occurs
lstOuman.Items.Add("OCIRead: " + k);
txtOuman.Text = k.ToString();
// l = pOIDATA.lData[0];
for (int i = OCI_MIN_INDEX; i < OCI_MAX_INDEX; i++)
{
long result = oci.OCIRead(lObject, lDevice, i, ref pOIDATA); //This is where error occurs
lstOuman.Items.Add(" " + i + " arvo: " + result );
//_EXPORT(long) OCIGetIndexInfo(long lIndex,char **pszInfo,long *plRead,long *plWrite);
long results = oci.OCIGetIndexInfo(i, "", ref plRead, ref plWrite);
lstOuman.Items.Add(" " + i + " info: " + results );
}
}
********* oci200.h ******************
/*******************************************************************************
Index struct
*******************************************************************************/
struct OIDATA
{
long lData[32]; // array of data, values depeds of index number
long lCheckAlarm; // when read request is done and this is > 0 user should check alarm
long lCategory; // when this is > 0 device configuration is changed
long lReadError; // read error is occured
char szData[128]; // raw index read data as comma separated
};
/*******************************************************************************
Function: OCIRead
Comments: Read index data from EHx device
Input: long lOIObject , connection handle
long lDevice, device index 0..x if more than 1 device in com line
long lIndex, index to read OCI_MIN_INDEX ... OCI_MAX_INDEX
struct OIDATA *pOIData, pointer to read data struct
Return: success, OCI_OK
failure, OCI_* error code
*******************************************************************************/
_EXPORT(long) OCIRead(long lOIObject,long lDevice,long lIndex,struct OIDATA *pOIData);
*******************************************************************************/
_EXPORT(long) OCIWrite(long lOIObject,long lDevice,long lIndex,struct OIDATA *pOIData);
/*******************************************************************************
Function: OCIGetIndexInfo
Comments: Get read/write index info
Input: long lIndex, index id value range OCI_MIN_INDEX ... OCI_MAX_INDEX
char ** pszInfo, pointer to description info
long *plRead, pointer to readable flag, if > 0 index can be read
long *plWrite, pointer to writable flag, if > 0 index can be write
Return: success, OCI_OK
failure, OCI_ERROR
*******************************************************************************/
_EXPORT(long) OCIGetIndexInfo(long lIndex,char **pszInfo,long *plRead,long *plWrite);
Programming is like sex:
One mistake and you have to support it for the rest of your life.
|
|
|
|
|
I need some detailed explanations about constructors using pointers.
|
|
|
|
|
Perhaps a specific question would be more appropriate?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
I am using VS 2010 Professional.
I am getting the error:
error C2143: syntax error : missing ';' before '*'
From:
Unmanaged *pu;
I assume there is something very simple that I am overlooking. This problem can be easily re-created. I re-created it by creating a Visual C++ CLR Class Librsry project. Then I used the Class Wizard to create an unmanaged class called Unmanaged. Then in the managed Class1 class I added the line shown above. Then I built that without any other changes and got the error. I do not understand why.
|
|
|
|
|
There is obviously something missing in your code such that the term Unmanaged is not being correctly interpreted by the compiler. Perhaps if you post your class definition also, someone can figure out what's wrong.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I am an idiot. I forgot to #include "Unmanaged.h". I definitely know better but for some reason I did not use my brain.
|
|
|
|
|
Sam Hobbs wrote: for some reason I did not use my brain.
You are now a certified developer; it's something we all do from time to time.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I have a simple function to check Totals on any table in my system (and similar ones for deleting and existence)
The parsed SQL is along these
Select Count(*) from AnyTable
Where ColumnA = 1
and ColumnB = 2
Written in C++/CLI as a command String
Select Count * from {0}
Where {1} = {2}
And {3} = {4}
Alternatively
And ({3} = {4} Or {3} is null} - This is controlled by an CallArgument driven switch construct.
~The function executing this statement takes the TableName, Column 1, Value 1, Column 2,Value 2 and CallArgument as parameters.
And this all works very well until I find I need a third Key/Value pair so I have to add to the parameters and recompile, amend my dynamic SQL etc.
I am thinking of passing in a list based on a class the members of which will be Key, Value, and NullAction.
Extending the parameter list and switch every time an extra clause has to be checked is a primitve and ugly looking approach by comparison to passing in the list and using a 'for each' loop to add a clause for what ever number of parameters are present.
This new approach has the added benefit of being low maintenance, in as far as possible, future proof.
But is it just style over substance?
Will there be a performance price to pay for passing in a list of key/values over specifiying each pair explicitly in the parameter list, subistuting in nullptr for the ones not required on any given call?
Note NullAction would controll whether or not a column needs to consider Null / not Null in an and / or capacity similar to the example above.
Ger
|
|
|
|
|
You shouldn't be building an SQL command string, instead use the SqlCommand class.
It has a Parameters property to which you can add whatever you consider relevant; in fact it does behave like a collection of key-value pairs. It also frees you from all the stringifying hassles, including DateTime format issues.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
I presume there is a MySQL equivalent...
It would be just what I need!
Ger
|
|
|
|
|
I don't know which data provider you are using, however even OdbcCommand has a Parameters property.
It is time for you to hit the documentation...
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Raided the hotpress last night and dug it out from its hiding place on the top shelf...
Ger
|
|
|
|
|
If you don't need the data, simple filering should always be done on the server side particulary if a lot of items will be rejected.
Philippe Mori
|
|
|
|
|
Hi,
When i try to register my DLL on my Windows XP machine, i get the following error.
Load Library (..) failed. The application has failed to start because the application configuration is incorrect. Reinstalling the application may fix the problem.
Any hints on how to fix this?
|
|
|
|
|
arc.dream wrote: Any hints on how to fix this?
Open the dll with Depends and see what dependency is missing.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
As told be wes there might be dependecies attached to your dll,try to find out them or you might using any old dll in your master dll which has not be renewed on that machine. Let me know if problem still persists.
One more thing, did you migrate this dll?
|
|
|
|
|
It seems that some of the dependent DLL or runtime is not present in the machine. You have to use dependency walker for solving this issue. This link[^] can help you.
|
|
|
|
|
Hi,
I have a COM dll with a class in it. This class alters the registry at HKLM\Software\Policies\MyPolicy
The DLL has a UAC execution level of Highest Available (I think I had it still happen with asInvoker as well).
The executable that cals this dll has an execution level of invoker.
If I run this as administrator, I get the UAC prompt when my class gets invoked, and I see all my debug messages in dbgview and any debug message boxes show up.
If I log in as standard user, and right click runas administrator, everything works fine.
However, If I simply double-click, I see the UAC elevation prompt when my class gets invoked. I enter in the correct password, and the COM object creation passes, but the Registry is never changed, AND I do not see any debug messages or message boxes. If I turn off "Run all administrators in admin approval mode", I see the messages, but the program fails to set the registry keys.
Anybody have any clues? Also, do you know of any great debuggers that I may use to solve this?
More Info:
I modified the DllRegisterServer function to add the following keys to the registry:
HKLM\Software\Classes\AppID\My AppGuid(found in dllMain.h)>\ROTFlags(a string set to "1")
HKLM\Software\Classes\AppID\My AppGuid\DllSurrogate(a string set to empty)
HKLM\Software\Classes\CLSID\My ClassID (found in ClassName.rgs)\AppID (a string set to My AppGuid)
HKLM\Software\Classes\CLSID\My ClassID\LocalizedString (an expanding string set to @dllPath.dll,-100(where 100 is a string
in the string table)).
HKLM\Software\Classes\CLSID\My ClassID\Elevation\Enabled (a DWORD set to 1)
HKLM\Software\Classes\CLSID\My ClassID\Elevation\IconReference (An expanding string set to 'applicationIcon')
Also, my calling code uses the standard old
HRESULT CallingClass::CoCreateInstanceAsAdmin(HWND hwnd,REFCLSID rClsid, REFIID rIid, void** ppv)
{
try
{
HRESULT hr;
BIND_OPTS3 bo;
WCHAR wszCLSID[255];
WCHAR wszMonikerName[300];
StringFromGUID2(rClsid,wszCLSID,sizeof(wszCLSID)/sizeof(wszCLSID[0]));
hr = StringCchPrintf(
wszMonikerName,sizeof
(wszMonikerName)/
sizeof(wszMonikerName[0]),
L"Elevation:Administrator!new:%s",
wszCLSID);
if(FAILED(hr))
{
. . .ShowMyDebugMessage
return hr;
}
memset(&bo, 0, sizeof(bo));
bo.cbStruct = sizeof(bo);
bo.hwnd = hwnd;
bo.dwClassContext = CLSCTX_LOCAL_SERVER;
return CoGetObject(wszMonikerName,
&bo, rIid, ppv );
}
catch(...)
{
. . .Show my debug message
return E_FAIL;
}
return S_OK;
}
Christine Murphy
C# developer
modified 25-Jan-12 15:40pm.
|
|
|
|
|