|
COM decrees that you always return an HRESULT from a method or property. Automation clients like VB and, to some degree .NET, translate retvals to return values for you. This can be controlled with the PreserveSigAttribute (although that's for RCWs, not CCWs like you're using here). So your cpi->returnTemperatureArray call should accept an [out, retval] as the last parameter and return an HRESULT (which .NET will for you based on whether or not you thrown an exception, or if you preserve the signature and return an error or success code).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
If you care in the description on your "Custom String Formatting in .NET" there is a 't' floating around....
You might want to fix it... you know the short description under the title on the topish....
/\ |_ E X E GG
|
|
|
|
|
Thanks. I'll get that fixed.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
So what i understand is that there is no way that a function with the following signature
in a C# DLL ,can be invoked by a win32/ATL client
[return :MarshalAs(UnmanagedType.LPArray)] int[] returnTemperatureAsArray(out int cnt);
Why do i not get this error with the following then ?
[return : MarshalAs(UnmanagedType.LPStr)] string GetWeatherAsANSI();
This seems to work fine when invoked from a win32 client.
|
|
|
|
|
You can, but the CCW (COM-Callable Wrapper) changes the int[] return value into an [out, retval] parameter at the end of the method, as it should be in COM since all methods (including property getter and putters) should return an HRESULT .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
What is the fastest way to render raw image bits to a Bitmap Object? I am not allowed to use unsafe code.
|
|
|
|
|
You mean basically what you'd pass to CreateDIBSection in Windows GDI? Well, you must know a few things about the bitmap data, like the width and height, or even just the stride (how many bytes in a line). You also need to know the pixel format, such as whether the data represents a 32-bit bitmap, 24-bit, etc.
Fortunately, with this information GDI+ (and System.Graphics ) makes this easy. Use the Bitmap(int, int, int, PixelFormat, IntPtr) constructor, which takes the width, height, stride, pixel format, and a pointer to the raw data, respectively.
Read more about that constructor in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
All I want to do is change the form1.Text property when I click a button?
Could someone provide me with a simple approach?
Thank you,
cb
|
|
|
|
|
form1.ActiveForm.Text = "Text goes here";
|
|
|
|
|
Thank you very much for your quick response.
I got hung up on using a "Layout" method and a few minutes ago figured out I needed a 'PerformMethod' call.
Arrrrrrrrrrrrrrrrgh! If I wanted to write that much code I'd do a novel.
Yours is a more straight fowrard approach and thanks.
BTW as a newbie ... you would'nt believe the Googling I did to try to resovle this apparently easy issue.
Issue closed, thanks again.
cb
|
|
|
|
|
You're Welcome.
I suggest getting a book, it will helpyou greatly to get started with C#.
|
|
|
|
|
How can I make sure my form stay on top of everything. I set the TopMostLevel to true, and it works when I work in windows. Then, I load a game and my form is hidden. Does the game take over the priority or what, and how do I change that?
Thanks
|
|
|
|
|
Games write directly to the screen buffer, not through GDI or GDI+ like Windows does. A system modal dialog would only appear atop a windowed-game, and good luck trying to find any decent ones these days.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
For me to write screen buffer, would I have to use DirectX or something of that sorts?
Thanks in advance.
|
|
|
|
|
You can, or you can P/Invoke the massive amount of APIs required to communicate with the display HAL, which doing in managed code (except, perhaps, Managed C++) would truly be a nightmare.
And just implementing DirectX won't necessary fix the problem: the game may not share its hold on the display device (or any other devices it's using). An exclusive lock may be used. Games like the older Everquest versions (according to my friend) did have such an exclusive lock and if you tried to circumvent the lock the game would crash and eventually your account would be locked out.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hey, I have a vertical splitter between two groupboxes but after i enabled
visualstyles in my application it doesnt work ok ,after i move it the
groupbox which is supposed to fill doesnt and i cant move the splitter any
more, Help , did anyone incounter this kind of problem?
|
|
|
|
|
Check if you set the "Align" property properly. When use splitter, you should set the "Align" property of the splitter as well as the groupbox.
|
|
|
|
|
thanks , but the splitter and groupbox dont have an align property.
|
|
|
|
|
Sorry, I make a mistake. It is the "Dock" property, not the "Align" property. See whether the codes below could work.
groupBox2.Dock = DockStyle.Fill;
splitter1.Dock = DockStyle.Left;
groupBox1.Dock = DockStyle.Left;
|
|
|
|
|
Does anyone know how, or seen a snippet/class for performing a name server lookup on a hostname? If you do and could share your knowledge that'd be appreciated.
|
|
|
|
|
Read about Dns.GetHostByName in the .NET Framework SDK. There's other helpful classes in the System.Net namespace you should read about as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks, I can see how the array returned could have the nameservers in. I actually found an opensource mail server (Lumisoft mailserver), which has one namespace: LumiSoft.Net.Dns that contains all I need: mx record lookup, name servers, CNAME, ptrs etc. Worth a look if anyone needs it, as it can be extracted from the whole class library without it breaking from dependencies
|
|
|
|
|
I'm new to C# and am having a hard time with a project I am working on. I work primarily with PeopleSoft, and we are interfacing to the PeopleSoft API via C#. I have a good example for VB 6 or C/C++, but am having problems wrapping it for C#.
Firstly, it uses a lot of #defines, not sure how to translate them into C#. Should I just use the raw codes. See below for the psmsgapi.h header file.
Secondly, many of the parameters used by the functional prototypes have structures or pointers.
Any help would be greatly appreciated!! My email is sfcarroll@yahoo.com
An example of a C program that will do what I am trying to do:
#include <string.h>
#include <stdio.h>
#include "/opt/psoft/hr762dev/src/inc/psmsgapi.h"
void PrintError(char *);
PSMSGHANDLE hCtx;
main()
{
PSOPERATOR Opr;
int Result;
int nReplyOption;
strcpy(Opr.szOprId, "USER");
strcpy(Opr.szOprPswd, "PASSWORD");
Result = PSMsgConnect(PSMSG_APIVERSION, "10.141.136.100:8030", &Opr, &hCtx);
if (Result != PSMSG_OK)
PrintError("Error in Connect");
Result = PSMsgStartMessage(hCtx, "HS_email_processing", "HS_update_email", 0);
if (Result != PSMSG_OK)
PrintError("Error in Start Message");
Result = PSMsgSetField(hCtx, "EMPLID", "000212");
if (Result != PSMSG_OK)
PrintError("Error in Setfield on emplid");
Result = PSMsgSetField(hCtx, "HS_EMAIL_ADDRESS", "sfcarroll@yahoo.com");
if (Result != PSMSG_OK)
PrintError("Error in Setfield on email address");
Result = PSMsgSetField(hCtx, "HS_DO_NOT_EMAIL", "Y");
if (Result != PSMSG_OK)
PrintError("Error in Setfield on email check box");
Result = PSMsgProcessMessage(hCtx, &nReplyOption);
if (Result != PSMSG_OK)
PrintError("Error in Process Message");
Result = PSMsgDisconnect(hCtx);
if (Result != PSMSG_OK)
PrintError("error in disconnect");
printf("!! SUCCESS !! \n");
return (0);
HEADER FILE - psmsgapi.h
#ifndef _INC_PSMSGAPI_H /* only include psmsgapi.h once */
#define _INC_PSMSGAPI_H
/***********************************************************************
* defines *
***********************************************************************/
// the API version number to be passed in to PSMsgConnect
#define PSMSG_APIVERSION 1
// API return codes
#define PSMSG_OK 0 // operation successful
#define PSMSG_ERROR 1 // general runtime error
#define PSMSG_NOTLOADED 2 // Message Agent not present
#define PSMSG_BADCONTEXT 3 // invalid PSMSGHANDLE
#define PSMSG_NOTFOUND 4 // requested definition not found
#define PSMSG_NOMATCHINGROWS 5 // no matching rows
#define PSMSG_NOMOREAGENTS 6 // no more free agents
// reply options for PSMsgProcessMessage
#define PSMSG_NOREPLY 0
#define PSMSG_REPLY 1
#define PSMSG_FORWARD 2
// Message Agent Option Flags - Multiple options can be OR'ed
#define PSMSG_OPT_RESET 0x000 // Reset all options
#define PSMSG_OPT_CHANGEMODEADDUPDATE 0x001 // change panel mode from add to
// update if level 0 record was
// found
#define PSMSG_OPT_NOGUI 0x002 // NO LONGER SUPPORTED - Disable GUI
#define PSMSG_OPT_NOFIELDEDITS 0x004 // NOT IMPLEMENTED
// Disable Field edits. This will
// stop checking for valid values
// for fields, so use it when you
// are reading validated values
// and pushing it back into
// application tables.
#define PSMSG_OPT_FIELDORDER 0x008 // Order outputlist by how they
// appear in Field Mapping
#define PSMSG_OPT_MODE_ADD 0x010 // Action mode flags
#define PSMSG_OPT_MODE_UPDATE 0x020
#define PSMSG_OPT_MODE_UPDATEALL 0x030
#define PSMSG_OPT_MODE_CORRECTION 0x040
#define PSMSG_OPT_MODE_DATAENTRY 0x050
#define PSMSG_OPT_MODE_MASK 0x0F0
#define PSMSG_OPT_UNFORMATTED_IN 0x100 // Input data are unformatted
#define PSMSG_OPT_UNFORMATTED_IN_OFF 0x200 // turn off UNFORMATTED_IN
#define PSMSG_CHANGEMODEADDUPDATE PSMSG_OPT_CHANGEMODEADDUPDATE
#define PSMSG_SEARCHMODE_EXACT 0
#define PSMSG_SEARCHMODE_LIKE 1
#define PSMSG_SEARCHMODE_PROMPT 2
// Constants used by/for PSMsgCheckAndSetOperator() function
#define PSMSG_OPERATORLEN 8 // Operator name length
// Constants used by/for PSMsgGetFieldList() function
#define PSMSG_FIELDNAMELEN 30 // Field name length
#define PSMSG_RECNAMELEN 15
#define PSMSG_USE_UNSUPPORTED 0x00000000 // Field mapping use(s)
#define PSMSG_USE_INPUT 0x00000001
#define PSMSG_USE_OUTPUT 0x00000002
#define PSMSG_USE_BOTH 0x00000003
#define PSMSG_USE_SEARCHKEY 0x00000004
#define PSMSG_USE_FIELDKEY 0x00000008
#define PSMSG_USE_REQUIRED 0x00000100
#define PSMSG_USE_EDITXLAT 0x00000200
#define PSMSG_USE_YESNO 0x00002000
#define PSMSG_USE_EDITTABLE 0x00004000
#define PSMSG_XFR_UNSUPPORTED 0 // Field mapping transfer method(s)
#define PSMSG_XFR_COPY 1
#define PSMSG_XFR_XLATS 2
#define PSMSG_XFR_XLATL 3
#define PSMSG_XFR_REVERSE 4
#define PSMSG_TYPE_UNSUPPORTED 0 // Field type(s)
#define PSMSG_TYPE_CHAR 1
#define PSMSG_TYPE_NUMBER 2
#define PSMSG_TYPE_DATE 3
#define PSMSG_TYPE_TIME 4
#define PSMSG_TYPE_DATETIME 5
// Additional Defines For Search Dialog Processing
// Note that these values must be synched up with those #define's
// found in rdmdefs.h
#define PSMSG_USE_KEY 0x001 // RDM_KEY
#define PSMSG_USE_DUPLKEY 0x002 // RDM_DUPLKEY
#define PSMSG_USE_ALTKEY 0x010 // RDM_ALTKEY
#define PSMSG_USE_LISTITEM 0x020 // RDM_LISTITEM
#define PSMSG_USE_DESCKEY 0x040 // RDM_DESCKEY
#define PSMSG_USE_SEARCHITEM 0x800 // RDM_SEARCHITEM
// as defined in pslen.h
#define PSMSG_LONGNAMELEN 30 // RDM_LONGNAMELEN
#define PSMSG_SHORTNAMELEN 15 // RDM_SHORTNAMELEN
#define PSMSG_MAXVALUELEN 30
// the PSMSGHANDLE is a unique 32-bit context identifier given to a user of
// the PeopleSoft Message Agent API when a connection is made
#ifdef _WIN32
#define MSGAPIFUNCTION int __stdcall
#else
#define MSGAPIFUNCTION int
#endif
typedef void *PSMSGHANDLE;
const char C_fmtPSMagReady[] = "PSMAG:Ready:%s";
typedef struct
{
char szFieldName[PSMSG_FIELDNAMELEN + 1]; // Field name
int fFieldType; // Field type
// - PSMSG_TYPE_CHAR
// - PSMSG_TYPE_NUMBER
// - PSMSG_TYPE_DATE
// - PSMSG_TYPE_TIME
// - PSMSG_TYPE_DATETIME
// - PSMSG_TYPE_UNSUPPORTED
int nFieldSize; // Field size in bytes
int fFieldMapUse; // Field use attribute(s)
// - PSMSG_USE_INPUT
// - PSMSG_USE_OUTPUT
// - PSMSG_USE_BOTH
// - PSMSG_USE_SEARCHKEY
int fFieldMapTransfer; // Field method attribute(s)
// - PSMSG_XFR_COPY
// - PSMSG_XFR_XLATS
// - PSMSG_XFR_XLATL
// - PSMSG_XFR_REVERSE
int nFieldLevel; // Field's scroll level
char szEditTable[PSMSG_RECNAMELEN + 1]; // Edit Table
} PSMSGFIELDINFO;
typedef PSMSGFIELDINFO *LPPSMSGFIELDINFO;
typedef struct // Search Field Info
{
char szFieldName [PSMSG_FIELDNAMELEN + 1]; // Field name
char szLongName[PSMSG_LONGNAMELEN + 1]; // Long name
char szShortName[PSMSG_SHORTNAMELEN + 1]; // Short name
int fFieldType; // Field type
// - PSMSG_TYPE_CHAR
// - PSMSG_TYPE_NUMBER
// - PSMSG_TYPE_DATE
// - PSMSG_TYPE_TIME
// - PSMSG_TYPE_DATETIME
// - PSMSG_TYPE_UNSUPPORTED
int nFieldSize; // Size in bytes
int fFieldUse; // Field attributes in hex
// - PSMSG_USE_KEY
// - PSMSG_USE_DUPLKEY
// - PSMSG_USE_ALTKEY
// - PSMSG_USE_DESCKEY
// - PSMSG_USE_SEARCHITEM
// - PSMSG_USE_LISTITEM
char szEditTable[PSMSG_RECNAMELEN + 1]; // Edit Table
} PSMSGSEARCHFIELD;
typedef PSMSGSEARCHFIELD *LPPSMSGSEARCHFIELD;
typedef struct // Search Dialog Results
{
char szFieldName[PSMSG_FIELDNAMELEN + 1]; // Field Name
char szValue[PSMSG_MAXVALUELEN + 1]; // Field value
int nFieldNameSize; // Field's size in bytes
int nValueSize; // Value's size in bytes
} PSMSGLISTBOXFIELDINFO;
typedef PSMSGLISTBOXFIELDINFO *LPPSMSGLISTBOXFIELDINFO;
typedef struct /* logon information structure */
{
char szOprId[PSMSG_OPERATORLEN + 1];
char szOprPswd[PSMSG_OPERATORLEN + 1];
} PSOPERATOR;
typedef PSOPERATOR *LPPSOPERATOR;
/***********************************************************************
* PSMSGAPI version 1 function prototypes *
***********************************************************************/
#if defined (__cplusplus)
extern "C"
{
#endif
/* Session Level Operations */
MSGAPIFUNCTION PSMsgCheckAndSetOperator(PSMSGHANDLE hContext,
LPPSOPERATOR lpOperator);
MSGAPIFUNCTION PSMsgConnect(long lMsgAPIVersion,
const char *lpcszTopic,
LPPSOPERATOR lpOperator,
PSMSGHANDLE *lphContext);
MSGAPIFUNCTION PSMsgDisconnect(PSMSGHANDLE hContext);
MSGAPIFUNCTION PSMsgSetOptions(PSMSGHANDLE hContext,
int fOptions);
/* Processing Messages */
MSGAPIFUNCTION PSMsgStartMessage(PSMSGHANDLE hContext,
const char *lpcszActivityName,
const char *lpcszMsgName,
int bOriginatorVerified);
MSGAPIFUNCTION PSMsgProcessMessage(PSMSGHANDLE hContext,
int *lpnReplyOption);
/* Field Level Operations */
MSGAPIFUNCTION PSMsgSetField(PSMSGHANDLE hContext,
const char *lpcszFieldName,
const char *lpcszValue);
MSGAPIFUNCTION PSMsgGetMaxFieldNameLength(PSMSGHANDLE hContext,
int *lpnLength);
MSGAPIFUNCTION PSMsgGetMaxValueLength(PSMSGHANDLE hContext,
int *lpnLength);
MSGAPIFUNCTION PSMsgFindField(PSMSGHANDLE hContext,
const char *lpcszFieldName);
MSGAPIFUNCTION PSMsgFindFirstField(PSMSGHANDLE hContext);
MSGAPIFUNCTION PSMsgFindNextField(PSMSGHANDLE hContext);
MSGAPIFUNCTION PSMsgFindNextOutputRow(PSMSGHANDLE hContext);
MSGAPIFUNCTION PSMsgGetFieldCount(PSMSGHANDLE hContext,
int *lpnCount);
MSGAPIFUNCTION PSMsgGetFieldList(PSMSGHANDLE hContext,
LPPSMSGFIELDINFO lpFields);
MSGAPIFUNCTION PSMsgGetFieldNameLength(PSMSGHANDLE hContext,
int *lpnLength);
MSGAPIFUNCTION PSMsgGetFieldName(PSMSGHANDLE hContext,
char *lpszFieldName,
int nSize);
MSGAPIFUNCTION PSMsgGetValueLength(PSMSGHANDLE hContext,
int *lpnLength);
MSGAPIFUNCTION PSMsgGetValue(PSMSGHANDLE hContext,
char *lpszValue,
int nSize);
/* Error Processing */
MSGAPIFUNCTION PSMsgGetErrorExplainTextLength(PSMSGHANDLE hContext,
int *lpnLength);
MSGAPIFUNCTION PSMsgGetErrorExplainText(PSMSGHANDLE hContext,
char *lpszExplainText, int nSize);
MSGAPIFUNCTION PSMsgGetErrorFieldName(PSMSGHANDLE hContext,
char *lpszErrorFieldName, int nSize);
MSGAPIFUNCTION PSMsgGetErrorFieldNameLength(
PSMSGHANDLE hContext, int *lpnLength);
MSGAPIFUNCTION PSMsgGetErrorRecordName(PSMSGHANDLE hContext,
char *lpszErrorRecordName,
int nSize);
MSGAPIFUNCTION PSMsgGetErrorRecordNameLength(
PSMSGHANDLE hContext,
int *lpnLength);
MSGAPIFUNCTION PSMsgGetErrorTextLength(PSMSGHANDLE hContext,
int *lpnLength);
MSGAPIFUNCTION PSMsgGetErrorText(PSMSGHANDLE hContext,
char *lpszErrorText,
int nSize);
/* Search Dialog Processing */
MSGAPIFUNCTION PSMsgGetSearchFieldCount(PSMSGHANDLE hContext,
int *lpnCount);
MSGAPIFUNCTION PSMsgGetSearchList(PSMSGHANDLE hContext,
LPPSMSGSEARCHFIELD lpSearchInfo);
MSGAPIFUNCTION PSMsgGetSearchRecord(PSMSGHANDLE hContext,
char *lpszSearchRecordName, int nSize);
MSGAPIFUNCTION PSMsgGetSearchRecordLength(PSMSGHANDLE hContext,
int *lpnLength);
MSGAPIFUNCTION PSMsgProcessSearchDialog(PSMSGHANDLE hContext,
#if defined (__cplusplus)
int nMaxRows = 0);
#else
int nMaxRows);
#endif
MSGAPIFUNCTION PSMsgProcessSearchDialogWithMode(PSMSGHANDLE hContext,
#if defined (__cplusplus)
int nMaxRows = 0,
int nMode = 0);
#else
int nMaxRows,
int nMode);
#endif
/* List Box Processing */
MSGAPIFUNCTION PSMsgFindFirstListBoxField(PSMSGHANDLE hContext);
MSGAPIFUNCTION PSMsgFindFirstListBoxRow(PSMSGHANDLE hContext);
MSGAPIFUNCTION PSMsgFindListBoxField(PSMSGHANDLE hContext,
const char *lpcszFieldName);
MSGAPIFUNCTION PSMsgFindListBoxRow(PSMSGHANDLE hContext,
int nRowIndex);
MSGAPIFUNCTION PSMsgFindNextListBoxField(PSMSGHANDLE hContext);
MSGAPIFUNCTION PSMsgFindNextListBoxRow(PSMSGHANDLE hContext);
MSGAPIFUNCTION PSMsgGetListBoxField(PSMSGHANDLE hContext,
LPPSMSGLISTBOXFIELDINFO lpFieldInfo);
MSGAPIFUNCTION PSMsgGetListBoxFieldCount(PSMSGHANDLE hContext,
int *lpnCount);
MSGAPIFUNCTION PSMsgGetListBoxRow(PSMSGHANDLE hContext,
LPPSMSGLISTBOXFIELDINFO lpRowInfo);
MSGAPIFUNCTION PSMsgGetListBoxRowCount(PSMSGHANDLE hContext,
int *lpnRowCount);
/* Edit Table Processing */
MSGAPIFUNCTION PSMsgFindFirstPromptValueRow(PSMSGHANDLE hContext);
MSGAPIFUNCTION PSMsgFindNextPromptValueRow(PSMSGHANDLE hContext);
MSGAPIFUNCTION PSMsgFindPromptValueRow(PSMSGHANDLE hContext,
int nRowIndex);
MSGAPIFUNCTION PSMsgGetEditTableFieldCount(PSMSGHANDLE hContext,
const char *lpcszRecordName,
int *lpnFieldCount);
MSGAPIFUNCTION PSMsgGetEditTableFieldList(PSMSGHANDLE hContext,
const char *lpcszRecordName,
LPPSMSGSEARCHFIELD lpRecordInfo);
MSGAPIFUNCTION PSMsgGetPromptValueFieldCount(PSMSGHANDLE hContext,
int *lpnFieldCount);
MSGAPIFUNCTION PSMsgGetPromptValueRow(PSMSGHANDLE hContext,
LPPSMSGLISTBOXFIELDINFO lpFieldInfo);
MSGAPIFUNCTION PSMsgGetPromptValueRowCount(PSMSGHANDLE hContext,
int *lpnRowCount);
MSGAPIFUNCTION PSMsgProcessPromptTable(PSMSGHANDLE hContext,
const char *lpcszRecordName,
#if defined (__cplusplus)
int nMaxRows = 0);
#else
int nMaxRows);
#endif
#if defined (__cplusplus)
} // extern "C"
#endif
#endif /* _INC_PSMSGAPI_H */
|
|
|
|
|
Declare #define s as const fields of a class, or as an enum .
This forum, however, is to help you with specific problems, not do your work for you. You were hired for this job and are expected to know about P/Invoke and marshaling. If you have specific questions, please ask, but don't expect us to translate all your code for you.
Besides, you just posted confidential information. You might want to read the comment in the middle of the source. I doubt PeopleSoft would be very happy.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks - I set the defines up as
public const int, seems to be compiling OK.
Since I am a beginner in C#, I don't really know about P/Invoke, marshaling etc. Would appreciate any help.
I am trying to create structures to replace the C structures, ie:
[StructLayout(LayoutKind.Sequential)]
public struct PSOPERATOR
{
public string szOprID;
public string szOprPswd;
}
But when I try to assign values I get an error. Do I need to overload '='???
PSOPERATOR Opr = new PSOPERATOR();
Opr.szOprID = "USER";
Opr.szOprPswd = "PASSWORD";
......PeopleSoftAccess\Class1.cs(112): Invalid token '=' in class, struct, or interface member declaration
|
|
|
|
|