PRB: J/Direct or P/Invoke Parameters Must Be Strongly Typed (325595)
The information in this article applies to:
- Microsoft Visual J# .NET (2002)
- Microsoft Visual J# .NET (2003)
This article was previously published under Q325595 SYMPTOMS An unhandled exception may occur during a call to native
code. CAUSE Because Visual J# .NET uses the .NET marshaling engine,
polymorphic parameters are no longer supported for native interoperating. The
.NET marshaler only supports marshaling of object types as either a Variant
(the default) or an interface when the object is a structure field.
For more information, see the "Default Marshaling for Objects" topic in the
Microsoft Developer Network (MSDN) .NET documentation. RESOLUTION The Microsoft Software Development Kit (SDK) for Java
documentation uses the native Win32 WinHelp function as an example scenario where a polymorphic parameter
might prove useful. The following is an excerpt:
Some Microsoft Win32 functions declare a parameter whose type depends on the value of another parameter. For example, the WinHelp function is declared as follows:
BOOL WinHelp(int hwnd, LPCTSTR szHelpFile, UINT cmd, DWORD dwData);
The dwData parameter can be any one of the following, depending on the value of the cmd parameter: a pointer to a String, a pointer to a MULTIKEYHELP structure, a pointer to a HELPWININFO, or a plain integer.
The Microsoft SDK for Java documentation goes on to explain that
there are two ways to declare such a parameter by using J/Direct: "Declare the parameter to be type Object ..." or "Use
overloading to declare a separate method for each possible type." The second
method is the only method that is supported in Visual J# .NET. See
the "More Information" section for a WinHelp code sample of the second method.
STATUSThis
behavior is by design.REFERENCES For more information about the .NET marshaling engine and
default marshaling behavior and type mapping, visit the following MSDN Web
site:
Modification Type: | Major | Last Reviewed: | 8/7/2003 |
---|
Keywords: | kbMarshal kbprb KB325595 |
---|
|