Passing va_list as function argument - vala

I've created a simple SO example demonstrating various ways to pass va_list as function arg. The problem I'm trying to solve is passing the va_list in a callback from a shared object to the main module.
/*libcode.vala shared library (libvala-0.38)*/
namespace SOTestLib {
public const string TESTSTR = "my test string";
public const string EXPECTFORMATSTR = "expect test:%s";
public const string EXPECTFORMATSTR_VA_ARG0 = "1==1";
public delegate bool delegatefnExpect (bool expression, string format, va_list valist);
public delegatefnExpect delfnExpect;
public delegate bool delegatefnString (string mystring);
public delegatefnString delfnString;
public string gTestStr;
public string gExpectResultStr;
private void show_string(string mystring) {
stdout.printf("show_string mystring[%s] gTestStr[%s]\n", mystring, gTestStr);
assert (mystring == gTestStr);
assert (delfnString != null);
delfnString(mystring);
}
private bool expect(bool expression, string sformat, ...) {
assert (delfnExpect != null);
assert (sformat == EXPECTFORMATSTR);
va_list _valist = va_list ();
gExpectResultStr = sformat.vprintf (_valist);
stdout.printf("expect[%s]\n", gExpectResultStr);
return delfnExpect(expression, sformat , _valist);
}
private void my_printf (string format, ...) {
va_list va_list = va_list ();
string res = format.vprintf (va_list);
stdout.puts (res);
}
public int run_demo() {
//REFER:https://valadoc.org/glib-2.0/string.vprintf.html
// Output: ``Shut up, K-9!``
my_printf ("Shut %s, %c-%d!\n", "up", 'K', 9);
gTestStr = TESTSTR;
show_string(TESTSTR);
expect(1 == 1, EXPECTFORMATSTR, EXPECTFORMATSTR_VA_ARG0);
return 0;
}
}
/*main.vala linked with libcode.so shared library (libvala-0.38)*/
using SOTestLib;
public bool cbfnString(string test_str) {
stdout.printf("cbfnString test_str[%s] gTestStr[%s]\n", test_str, gTestStr);
assert (test_str == gTestStr);
return true;
}
public bool cbfnExpect(bool expression, string format, va_list args) {
stdout.printf("cbfnExpect format[%s] format.length[%d]\n",
format, format.length);
assert (format == EXPECTFORMATSTR);
string res = format.vprintf(args);
assert (res != null);
stdout.printf("cbfnExpect res[%s] gExpectResultStr[%s]\n", res, gExpectResultStr);
assert(res == gExpectResultStr);
return expression;
}
static int main(string[] args) {
delfnString = (delegatefnString)cbfnString;
delfnExpect = (delegatefnExpect)cbfnExpect;
return run_demo();
}
Here is the result of running the test...
===========================================================================
---Run main --
===========================================================================
./stackoverflow/libcallback_strings/lib/libcallback_strings.exe
Shut up, K-9!
show_string mystring[my test string] gTestStr[my test string]
cbfnString test_str[my test string] gTestStr[my test string]
expect[expect test:1==1]
cbfnExpect format[expect test:%s] format.length[14]
cbfnExpect res[expect test:(null)] gExpectResultStr[expect test:1==1]
**
ERROR:/media/george/SharedData/Projects/Vala/LanguageServer/stackoverflow/libcallback_strings/main.vala:15:cbfnExpect: assertion failed: (res == gExpectResultStr)
stackoverflow/so_examples.mk:252: recipe for target 'libcallback_strings' failed
make: *** [libcallback_strings] Aborted
The terminal process terminated with exit code: 2
For some reason in cbfnExpect, va_list args is no longer valid. It seems as if va_list address (or addresses within the struct) is only valid within the shared library. Is this not the correct/allowed usage of va_list?

In private bool expect, if I comment out setting gExpectResultStr as follows:
//gExpectResultStr = sformat.vprintf (_valist);
Then, in the first line of the static int main method, I added:
gExpectResultStr = "expect test:1==1";
The test passes. Since gExpectResultStr is the same every time the program is run, I just statically set it to the correct value when the program starts. Removing the call to vprintf in expect seems to be what fixes it.
My guess is that calling sformat.vprintf on the va_list, under the hood, in the C implementation, invalidates the va_list.
When diffing the generated C code for both the passing and failing code, here is what I came up with. Staring at the code for a while, the only potential part that might mess up the va_list is the call to g_strdup_vprintf(). I guess that function frees the va_list?
$ diff -Naur libcode-pass.c libcode-fails.c
--- libcode-pass.c 2018-01-20 09:19:24.455838766 -0800
+++ libcode-fails.c 2018-01-20 09:19:59.631260461 -0800
## -66,26 +66,32 ##
SOTestLibdelegatefnExpect _tmp0_;
const gchar* _tmp1_;
va_list _valist = {0};
- FILE* _tmp2_;
- const gchar* _tmp3_;
- SOTestLibdelegatefnExpect _tmp4_;
- gboolean _tmp5_;
- const gchar* _tmp6_;
+ const gchar* _tmp2_;
+ gchar* _tmp3_;
+ FILE* _tmp4_;
+ const gchar* _tmp5_;
+ SOTestLibdelegatefnExpect _tmp6_;
gboolean _tmp7_;
+ const gchar* _tmp8_;
+ gboolean _tmp9_;
g_return_val_if_fail (sformat != NULL, FALSE);
_tmp0_ = so_test_lib_delfnExpect;
_vala_assert (_tmp0_ != NULL, "delfnExpect != null");
_tmp1_ = sformat;
_vala_assert (g_strcmp0 (_tmp1_, SO_TEST_LIB_EXPECTFORMATSTR) == 0, "sformat == EXPECTFORMATSTR");
va_start (_valist, sformat);
- _tmp2_ = stdout;
- _tmp3_ = so_test_lib_gExpectResultStr;
- fprintf (_tmp2_, "expect[%s]\n", _tmp3_);
- _tmp4_ = so_test_lib_delfnExpect;
- _tmp5_ = expression;
- _tmp6_ = sformat;
- _tmp7_ = _tmp4_ (_tmp5_, _tmp6_, _valist);
- result = _tmp7_;
+ _tmp2_ = sformat;
+ _tmp3_ = g_strdup_vprintf (_tmp2_, _valist);
+ _g_free0 (so_test_lib_gExpectResultStr);
+ so_test_lib_gExpectResultStr = _tmp3_;
+ _tmp4_ = stdout;
+ _tmp5_ = so_test_lib_gExpectResultStr;
+ fprintf (_tmp4_, "expect[%s]\n", _tmp5_);
+ _tmp6_ = so_test_lib_delfnExpect;
+ _tmp7_ = expression;
+ _tmp8_ = sformat;
+ _tmp9_ = _tmp6_ (_tmp7_, _tmp8_, _valist);
+ result = _tmp9_;
va_end (_valist);
return result;
}

Related

Access Lua coroutine from C

I have implemented a co-routine system. When I press ENTER to clear the first textbox, it calls contscript() which in turn calls lua_resume() but it doesn't continue the co-routine.
So what do I pass to lua_resume() to make the co-routine continue?
static lua_State *lua;
static int luapanic(lua_State *L)
{
allegro_exit();
const char *err = lua_tostring(L, -1);
DEBUGF("lua panic: %s\n", err);
printf("lua panic: %s\n", err);
return 0;
}
static int textbox(lua_State *L)
{
const char *str = luaL_checkstring(L, 1);
message(str);
return 1;
}
void contscript(void)
{
lua_resume(lua,NULL,0);
}
static int transfer_player(lua_State *L)
{
int x, y;
SpriteObj *p;
x = luaL_checkint(L, 1);
y = luaL_checkint(L, 2);
p = findobject(0);
setposition(p,x,y);
scrollToAndCentre(x,y);
return 1;
}
bool initscript(void)
{
lua = luaL_newstate();
lua_atpanic(lua, luapanic);
luaL_openlibs(lua);
lua_register(lua, "textbox", textbox);
lua_register(lua, "transfer_player", transfer_player);
return true;
}
Here is the script in question:
local co = coroutine.wrap(
function()
textbox("Dear me! I never knew birds could sing so\nbeautifully!")
coroutine.yield()
textbox("Text message #2")
end
)
co()

One function gives several results in swift

I have a method in objective-C which I call from swift. It worked pretty well in swift 2, but in swift 3 the behaviour has changed. It gives me 3 different results, even though I send the same parameters.
Sometimes it doesnt find pfile, sometimes it fails on pin checking, sometimes works good and gives me x509.
char* ParsePKCS12(unsigned char* pkcs12_path, unsigned char * pin) {
printf("PARSE PATH: %s\n", pkcs12_path);
printf("PASSWORD: %s\n", pin);
NSString *pfile = [NSString stringWithUTF8String:pkcs12_path];
FILE *fp;
PKCS12 *p12;
EVP_PKEY *pkey;
X509 *cert;
BIO *databio = BIO_new(BIO_s_mem());
STACK_OF(X509) *ca = NULL;
if([[NSFileManager defaultManager] fileExistsAtPath:pfile]) {
NSLog(#"ok, pfile exists!");
} else {
NSLog(#"error, pfile does not exists!");
return "-1";
}
OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();
fp = fopen([pfile UTF8String], "rb");
p12 = d2i_PKCS12_fp(fp, NULL);
fclose (fp);
if (!p12) {
fprintf(stderr, "Error reading PKCS#12 file\n");
ERR_print_errors_fp(stderr);
return "-1";
}
if (!PKCS12_parse(p12, (const char *)pin, &pkey, &cert, &ca)) { //Error at parsing or pin error
fprintf(stderr, "Error parsing PKCS#12 file\n");
ERR_print_errors_fp(stderr);
ERR_print_errors(databio);
return "-1";
}
BIO *bio = NULL;
char *pem = NULL;
if (NULL == cert) {
//return NULL;
return "-1";
}
bio = BIO_new(BIO_s_mem());
if (NULL == bio) {
return "-1";
}
if (0 == PEM_write_bio_X509(bio, cert)) {
BIO_free(bio);
//return NULL;
}
pem = (char *) malloc(bio->num_write + 1);
if (NULL == pem) {
BIO_free(bio);
return "-1";
}
memset(pem, 0, bio->num_write + 1);
BIO_read(bio, pem, bio->num_write);
BIO_free(bio);
PKCS12_free(p12);
return pem;
}
this code I call in swift like this:
self.x509 = String(cString:ParsePKCS12(UnsafeMutablePointer<UInt8>(mutating: self.path),
UnsafeMutablePointer<UInt8>(mutating: "123456"))!)
Your call
self.x509 = String(cString:ParsePKCS12(UnsafeMutablePointer<UInt8>(mutating: self.path),
UnsafeMutablePointer<UInt8>(mutating: "123456"))!)
does not work reliably because in both
UnsafeMutablePointer<UInt8>(mutating: someSwiftString)
calls, the compiler creates a temporary C string representation of
the Swift string and passes that to the function. But that C string
is only valid until the UnsafeMutablePointer constructor returns, which means that the second
string conversion can overwrite the first, or any other undefined
behaviour.
The simplest solution would be to change the C function to
take constant C strings (and use the default signedness):
char* ParsePKCS12(const char * pkcs12_path, const char * pin)
Then you can simply call it as
self.x509 = String(cString: ParsePKCS12(self.path, "123456"))
and the compiler creates temporary C strings which are valid during
the call of ParsePKCS12().

Data From Arduino Yun To Google Spreadsheet

I am working on a project where I am sending a timestamp from and Arduino Yun to a Google Spreadsheet. I have a PIR Sensor connected to the Yun. When motion is detected I am sending the value to the spreadsheet. Currently the value is going into one column.
This is not ideal because I want to create a chart from the data so I want the time and date to be in two different columns. Like the sample below.
Arduino Sketch
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h"
#include <Process.h>
int pir_pin = 8;
Process date;
int hours, minutes, seconds;
int lastSecond = -1;
const String GOOGLE_CLIENT_ID = "";
const String GOOGLE_CLIENT_SECRET = "";
const String GOOGLE_REFRESH_TOKEN = "";
const String SPREADSHEET_TITLE = "";
int numRuns = 1;
int maxRuns = 100;
void setup() {
Serial.begin(9600);
delay(4000);
pinMode(pir_pin, INPUT);
while (!Serial);
Serial.println("Time Check");
if (!date.running()) {
date.begin("date");
date.addParameter("+%T %D");
date.run();
}
Serial.print("Initializing the bridge... ");
Bridge.begin();
Serial.println("Done!\n");
}
void loop()
{
if (digitalRead(pir_pin) == true) {
if (!date.running()) {
date.begin("date");
date.addParameter("+%T %D");
date.run();
}
while (date.available() > 0) {
String timeString = date.readString();
int firstColon = timeString.indexOf(":");
int secondColon = timeString.lastIndexOf(":");
String hourString = timeString.substring(0, firstColon);
String minString = timeString.substring(firstColon + 1, secondColon);
String secString = timeString.substring(secondColon + 1);
hours = hourString.toInt();
minutes = minString.toInt();
lastSecond = seconds;
seconds = secString.toInt();
if (numRuns <= maxRuns) {
Serial.println("Running AppendRow - Run #" + String(numRuns++));
unsigned long now = millis();
Serial.println("Getting sensor value...");
Serial.println("Appending value to spreadsheet...");
TembooChoreo AppendRowChoreo;
AppendRowChoreo.begin();
AppendRowChoreo.setAccountName(TEMBOO_ACCOUNT);
AppendRowChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
AppendRowChoreo.setAppKey(TEMBOO_APP_KEY);
AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow");
AppendRowChoreo.addInput("ClientID", GOOGLE_CLIENT_ID);
AppendRowChoreo.addInput("ClientSecret", GOOGLE_CLIENT_SECRET);
AppendRowChoreo.addInput("RefreshToken", GOOGLE_REFRESH_TOKEN);
AppendRowChoreo.addInput("SpreadsheetTitle", SPREADSHEET_TITLE);
String rowData = timeString;
AppendRowChoreo.addInput("RowData", rowData);
unsigned int returnCode = AppendRowChoreo.run();
if (returnCode == 0) {
Serial.println("Success! Appended " + rowData);
Serial.println("");
} else {
while (AppendRowChoreo.available()) {
char c = AppendRowChoreo.read();
Serial.print(c);
}
}
AppendRowChoreo.close();
}
Serial.println("Waiting...");
delay(5000);
}
}
}
How would I alter the code to achieve the above.
I work for Temboo.
You can set multiple columns in the AppendRow Choreo by separating each value in rowData with a comma. For your case, you'd want your rowData to look like this: "19:35:26,4/22/2016". You could try something like timeString.replace(" ",",");.
Hopefully this helps. If you have any other questions, feel free to contact us at https://temboo.com/support

Memory Leak in C and C++ Code

I am trying to return a pointer from a function and use the return in a different function but I am getting memory leak.
The test code which I wrote and detected with memory leak by CPPCheck.
########################################################################
# include < stdio.h >
# include < malloc.h >
# include < string.h >
char* replace ( char* st, char* word, char *replaceWith );
int main ( void )
{
char str[] = "Hello how are ## and what are ## doing ?";
char word[]="##";
char replaceWith[]="you";
printf("%s",replace(str,word,replaceWith));
getchar();
return 0;
}
char* replace(char* st,char* word,char *replaceWith)
{
int i = 0;
char *sr,*s,*ret;
int oldlen;
int count = 0;
int newlen;
int stlen;
s=(char *)malloc(strlen(st) + 1);
strcpy(s, st);
oldlen=strlen(word);
newlen=strlen(replaceWith);
for (i = 0; s[i]! = '\0'; )
{
if( memcmp( &s[i], word, oldlen ) == 0)
{
count++;
i+=oldlen;
}
else
{
i++;
}
}
sr= (char *) malloc (i+1+count*(newlen-oldlen));
ret = (char *) malloc (i+1+count*(newlen-oldlen));
ret=sr;
while(*s)
{
if(memcmp( s, word, oldlen) == 0)
{
memcpy(sr, replaceWith, newlen);
s+ = oldlen;
sr+ = newlen;
}
else
{
*sr++ = *s++;
}
}
*sr = '\0';
return ret;
}
Try this
#include<stdio.h>
#include<malloc.h>
#include<string.h>
char* replace ( char* st, char* word, char *replaceWith );
int main ( void )
{
char str[] = "Hello how are ## and what are ## doing ?";
char word[]="##";
char replaceWith[]="you";
char * ret = replace(str,word,replaceWith);
printf("%s",ret);
free(ret); //freeing the allocated memory
getchar();
return 0;
}
char* replace(char* st,char* word,char *replaceWith)
{
int i = 0;
char *sr,*s,*ret, *temps;
int oldlen;
int count = 0;
int newlen;
int stlen;
s=(char *)malloc(strlen(st) + 1);
temps = s; // storing the address of s in a temp location
strcpy(s, st);
oldlen=strlen(word);
newlen=strlen(replaceWith);
for (i = 0; s[i]!= '\0';)
{
if( memcmp( &s[i], word, oldlen ) == 0)
{
count++;
i+=oldlen;
}
else
{
i++;
}
}
sr= (char *) malloc (i+1+count*(newlen-oldlen));
ret=sr;
while(*s)
{
if(memcmp( s, word, oldlen) == 0)
{
memcpy(sr, replaceWith, newlen);
s += oldlen;
sr += newlen;
}
else
{
*sr++ = *s++;
}
}
*sr = '\0';
free(temps); // freeing the memory allocated for s
return ret;
}
Always free same count with malloc.
free s, sr at end of replace,
use return value of replace instead of direct use on printf
and free return value (return of ret from replace) when not needed.
I have doing lots of experimenting with the memory leak and meanwhile I wrote the following code. Please comment about the pros and cons side of it.
#include <stdio.h>
#include <string.h>
#include <malloc.h>
// Prototype declaration of replaceAll function
static char* replaceAll(char *pSource, char *pWord, char*pWith);
/////////////////////////////////////////////////////////////////////////////
//
// NAME : main
//
// DESCRIPTION : Implementation of main which invokes the replaceAll
// function and displays the output
//
// PARAMETERS : void
//
// RETURNED VALUE : int
//
/////////////////////////////////////////////////////////////////////////////
int main( void )
{
char *finalString = NULL; // To save the base returned address
char srcString[] = "Hello how r you"; // Actual String
char pWord[] = "r"; // Word to be replaced
char pWith[] = "are"; // Word to be replaced with
printf("\n Before Calling the replaceAll function:");
printf("%s",srcString);
printf("\n");
finalString = replaceAll(srcString, pWord, pWith); //calling the replaceAll function
printf("\n After Calling the replaceAll function:");
// Checking if NULL is returned
if( finalString != NULL )
{
//printing the string
printf("%s", finalString);
}
else
{
printf("\n Error: Blank String returned ");
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////
//
// NAME : replaceAll
//
// DESCRIPTION : Implementation of replaceAll function which replaces
// a word in given string with another word
//
// PARAMETERS : char *
//
// RETURNED VALUE : char *
//
/////////////////////////////////////////////////////////////////////////////
static char* replaceAll(char *pSource, char *pWord, char*pWith)
{
char *pSt = NULL; // Pointer to the source String to avoid modifying the pSource
char *pTarget = NULL; // Target pointer to be malloced
char *pTg = NULL; // Pointer to the target string
int count; // Counter
int nWord = strlen (pWord); // length of the word which needs to be replaced
int nWith = strlen (pWith); // length of the word with which the word needs to be replaced
static const char nullP = '\0'; // null character
int szTarget = 0;
// Assigning the base address of the pSource to a temporary and iterate through
for ( pSt = pSource, count = 0; *pSt != nullP; pSt++ )
{
// Count number of occurances of the Word in the String to calculate the length of the final string
if( memcmp( pSt, pWord, nWord ) == 0)
{
count++;
pSt += nWord-1;
}
}
// Calculate the required target Size
szTarget = strlen (pSource) + count * (nWith - nWord) + sizeof (nullP);
// Allocate memory for the target string
pTarget = (char *)malloc(szTarget);
// Check if the malloc function returns sucessfully
if ( pTarget != NULL)
{
// Copying the string with replacement
for (pTg = pTarget, pSt = pSource; *pSt != nullP; )
{
if( memcmp (pSt, pWord, nWord) == 0)
{
memcpy (pTg,pWith,nWith);
pSt += nWord;
pTg += nWith;
}
else
{
*pTg++ = *pSt++;
}
}
// Assigning NULL Character to the target string after copying
*pTg = '\0';
}
return pTarget;
}

Reading windows logs using jna

I am getting an exception while reading windows logs using jna
Following is the program, I am using to read the logs. I took this program from another post.
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.util.Arrays;
import com.sun.jna.*;
import com.sun.jna.platform.win32.*;
import com.sun.jna.platform.win32.WinNT.*;
import com.sun.jna.ptr.IntByReference;
public class Test {
public static void main(String[] args) throws NumberFormatException, IOException {
HANDLE h = com.sun.jna.platform.win32.Advapi32.INSTANCE.OpenEventLog(null, "Application");
IntByReference pnBytesRead = new IntByReference();
IntByReference pnMinNumberOfBytesNeeded = new IntByReference();
IntByReference pOldestRecord = new IntByReference();
assertTrue(com.sun.jna.platform.win32.Advapi32.INSTANCE.GetOldestEventLogRecord(h, pOldestRecord));
int dwRecord = pOldestRecord.getValue();
System.out.println("OLD: " + dwRecord);
IntByReference pRecordCount = new IntByReference();
assertTrue(com.sun.jna.platform.win32.Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, pRecordCount));
int dwRecordCnt = pRecordCount.getValue();
System.out.println("CNT: " + dwRecordCnt);
int bufSize = 0x7ffff; //(r.size()) * 2048;
Memory buffer = new Memory(bufSize);
int rc = 0;
int cnt = 0;
while(com.sun.jna.platform.win32.Advapi32.INSTANCE.ReadEventLog(h,
WinNT.EVENTLOG_SEEK_READ /*
| WinNT.EVENTLOG_SEQUENTIAL_READ */
| WinNT.EVENTLOG_FORWARDS_READ /*
| WinNT.EVENTLOG_BACKWARDS_READ*/
,
dwRecord, buffer,
bufSize,
pnBytesRead,
pnMinNumberOfBytesNeeded)) {
rc = Kernel32.INSTANCE.GetLastError();
if (rc == W32Errors.ERROR_INSUFFICIENT_BUFFER) {
break;
}
int dwRead = pnBytesRead.getValue();
Pointer pevlr = buffer;
while (dwRead > 0)
{
cnt++;
EVENTLOGRECORD record = new EVENTLOGRECORD(pevlr);
System.out.println("------------------------------------------------------------");
System.out.println(cnt+". " + dwRecord + " Event ID: " + record.EventID.shortValue() + " SID: " + record.UserSidLength);
dwRecord++;
// WCHAR SourceName[]
// WCHAR Computername[]
{
ByteBuffer names = pevlr.getByteBuffer(record.size(),
(record.UserSidLength.intValue() != 0 ? record.UserSidOffset.intValue() : record.StringOffset.intValue()) - record.size());
names.position(0);
CharBuffer namesBuf = names.asCharBuffer();
String[] splits = namesBuf.toString().split("\0");
System.out.println("SOURCE NAME: \n" + splits[0]);
System.out.println("COMPUTER NAME: \n" + splits[1]);
}
// SID UserSid
if (record.UserSidLength.intValue() != 0){
ByteBuffer sid = pevlr.getByteBuffer(record.UserSidOffset.intValue(), record.UserSidLength.intValue());
sid.position(0);
//CharBuffer sidBuf = sid.asCharBuffer();
byte[] dst = new byte[record.UserSidLength.intValue()];
sid.get(dst);
System.out.println("SID: \n" + Arrays.toString(dst));
}
else {
System.out.println("SID: \nN/A");
}
// WCHAR Strings[]
{
ByteBuffer strings = pevlr.getByteBuffer(record.StringOffset.intValue(), record.DataOffset.intValue() - record.StringOffset.intValue());
strings.position(0);
CharBuffer stringsBuf = strings.asCharBuffer();
System.out.println("STRINGS["+record.NumStrings.intValue()+"]: \n" + stringsBuf.toString());
}
// BYTE Data[]
{
ByteBuffer data = pevlr.getByteBuffer(record.DataOffset.intValue(), record.DataLength.intValue());
data.position(0);
CharBuffer dataBuf = data.asCharBuffer();
System.out.println("DATA: \n" + dataBuf.toString());
}
// CHAR Pad[]
// DWORD Length;
dwRead -= record.Length.intValue();
pevlr = pevlr.share(record.Length.intValue());
}
}
assertTrue(rc == W32Errors.ERROR_HANDLE_EOF);
assertTrue(com.sun.jna.platform.win32.Advapi32.INSTANCE.CloseEventLog(h));
}
private static void assertTrue(boolean getOldestEventLogRecord) {
}
}
The Exception is as follows :-
Exception in thread "main" java.lang.NoSuchMethodError: com.sun.jna.IntegerType.
<init>(IJZ)V
at com.sun.jna.platform.win32.WinDef$DWORD.<init>(WinDef.java:57)
at com.sun.jna.platform.win32.WinDef$DWORD.<init>(WinDef.java:53)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at com.sun.jna.NativeMappedConverter.defaultValue(NativeMappedConverter.java:47)
at com.sun.jna.NativeMappedConverter.<init>(NativeMappedConverter.java:41)
at com.sun.jna.NativeMappedConverter.getInstance(NativeMappedConverter.java:29)
at com.sun.jna.Structure.calculateSize(Structure.java:803)
at com.sun.jna.Structure.useMemory(Structure.java:254)
at com.sun.jna.Structure.useMemory(Structure.java:238)
at com.sun.jna.Structure.<init>(Structure.java:174)
at com.sun.jna.Structure.<init>(Structure.java:167)
at com.sun.jna.Structure.<init>(Structure.java:163)
at com.sun.jna.platform.win32.WinNT$EVENTLOGRECORD.<init>(WinNT.java:1789)
at Test.main(Test.java:54)
Please help me out from the trouble. Thanks a lot in advance. I am new to this great site so, please excuse me for bad explanation
You cannot use different versions of platform.jar and jna.jar. That is what is causing your error. Both are distributed together, so I don't understand why you're using one version of one with a different version of the other.

Resources